Skip to content

Instantly share code, notes, and snippets.

View matifdeveloper's full-sized avatar
🎯
Focusing

Muhammad Atif matifdeveloper

🎯
Focusing
View GitHub Profile
@matifdeveloper
matifdeveloper / main.dart
Last active October 16, 2023 05:42
Format Time (AM - PM)
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)
@matifdeveloper
matifdeveloper / main.dart
Last active October 12, 2023 10:44
Birthday Calculator
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");
@matifdeveloper
matifdeveloper / main.dart
Created October 12, 2023 10:41
Yesterday Date
void main() {
final dateTime = DateTime.now().subtract(const Duration(days:1));
print(dateTime);
}
@matifdeveloper
matifdeveloper / main.dart
Created October 16, 2023 03:57
Random Number
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');
@matifdeveloper
matifdeveloper / main.dart
Created October 16, 2023 04:22
Remove common values from two Lists
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;
@matifdeveloper
matifdeveloper / main.dart
Created October 16, 2023 18:25
UK Driving Licence Regex
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)) {
@matifdeveloper
matifdeveloper / main.dart
Created November 9, 2023 04:39
Check the String is URL or not
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;
@matifdeveloper
matifdeveloper / main.dart
Created January 17, 2024 09:32
Scroll on button to specific widget
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@matifdeveloper
matifdeveloper / main.dart
Created January 19, 2024 04:52
Text Inside Brackets
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)!;
@matifdeveloper
matifdeveloper / main.dart
Created January 19, 2024 04:54
Text Inside Brackets
extension StringExtension on String {
String? getTextInsideBrackets() {
RegExp regExp = RegExp(r'\[([^\]]*)\]');
RegExpMatch? match = regExp.firstMatch(this);
return match?.group(1);
}
}
void main() {