This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
List<String> timeStrings = [ | |
"1 AM", "2 AM", "3 AM", "4 AM", "5 AM", "6 AM", "7 AM", "8 AM", "9 AM", "10 AM", "11 AM", "12 AM", | |
"1 PM", "2 PM", "3 PM", "4 PM", "5 PM", "6 PM", "7 PM", "8 PM", "9 PM", "10 PM", "11 PM", "12 PM" | |
]; | |
int index = 15; // Replace with the index you want to retrieve (0-based) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String dateString = "19/8/1998"; // Replace with your date string | |
List<String> dateComponents = dateString.split('/'); | |
if (dateComponents.length == 3) { | |
int day = int.parse(dateComponents[0]); | |
int month = int.parse(dateComponents[1]); | |
print("Day: $day"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final dateTime = DateTime.now().subtract(const Duration(days:1)); | |
print(dateTime); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
void main() { | |
// Create a random number generator | |
Random random = Random(); | |
// Generate a random integer between 1 and 1000 | |
int randomValue = random.nextInt(1000) + 1; | |
print('Random value between 1 and 1000: $randomValue'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
List a = [1,2,3,4,5]; | |
List b = [6,7,8,9,1]; | |
Map<int, int> commonData = {}; | |
int maxLength = a.length > b.length ? a.length : b.length; | |
int minLength = a.length < b.length ? a.length : b.length; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:core'; | |
bool isValidUKDrivingLicense(String input) { | |
RegExp regex = RegExp(r'^[A-Z9]{5}\d{6}[A-Z9]{2}\d[A-Z]{2}$'); | |
return regex.hasMatch(input); | |
} | |
void main() { | |
String drivingLicense = 'BILAL002031M99ZE'; // Replace with your driving license number | |
if (isValidUKDrivingLicense(drivingLicense)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print(isURL('https://dartpad.dev/?')); | |
} | |
bool isURL(String value) { | |
final uri = Uri.parse(value); | |
if (uri.scheme == 'http' || uri.scheme == 'https') { | |
return true; | |
} else { | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String a = "Hello welcome [to] pakistan."; | |
RegExp regExp = RegExp(r'\[([^\]]*)\]'); | |
// Option 1: Declare match as nullable | |
RegExpMatch? match = regExp.firstMatch(a); | |
// Option 2: Use the null-aware operator (!) to assert non-null | |
// Match match = regExp.firstMatch(a)!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension StringExtension on String { | |
String? getTextInsideBrackets() { | |
RegExp regExp = RegExp(r'\[([^\]]*)\]'); | |
RegExpMatch? match = regExp.firstMatch(this); | |
return match?.group(1); | |
} | |
} | |
void main() { |
OlderNewer