Skip to content

Instantly share code, notes, and snippets.

View GAM3RG33K's full-sized avatar

GAM3RG33K

View GitHub Profile
@GAM3RG33K
GAM3RG33K / custom_webview.dart
Last active May 10, 2021 13:57
[Flutter] How to use basic features of web view
Future<void> _showDemoPage(BuildContext context, String url) async {
final parameters = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => CustomWebView(
initialUrl: url,
),
),
);
print('AppHome: _showDemoPage: parameters: $parameters');
@GAM3RG33K
GAM3RG33K / countdown_timer.dart
Last active May 7, 2021 06:39
[Flutter] A countdown timer widget using overlay [With color animation]
import 'package:flutter/material.dart';
import 'package:timer_count_down/timer_count_down.dart';
class CountdownTimer extends StatefulWidget {
final Duration timerDuration;
final VoidCallback onComplete;
final String Function(double seconds) formatTimerString;
final Color startColor;
final Color endColor;
@GAM3RG33K
GAM3RG33K / PasswordValidator.dart
Created April 26, 2021 12:38
Flutter/Dart password validator
final FormFieldValidator<String> passwordValidator = (String value) {
// 1 lowercase, 1 uppercase, 1 number, 1 special character & at least 8 characters long
final regExp =
RegExp(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$');
final hasMatch = regExp.hasMatch(value);
if (!hasMatch) {
return 'Password should be:'
'\n - At least one lowercase, uppercase character'
'\n - At least one numeric characters'
@GAM3RG33K
GAM3RG33K / main.dart
Created April 20, 2021 10:02
using condition to fill more data in a collection
void main() {
_executeProcess1();
_executeProcess1(isAdvanced: true);
}
void _executeProcess1({bool isAdvanced = false}){
final list1 = [
1,2,3,4, if(isAdvanced)...[5,6,7,8,9,10,],];
@GAM3RG33K
GAM3RG33K / network_utils.dart
Created March 24, 2021 13:52
[Dart] Network utility functions
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
const defaultTimeoutDuration = Duration(seconds: 30);
/// This method is used to send an HTTP POST request
/// with given [url]. The response will be
@GAM3RG33K
GAM3RG33K / main.dart
Created March 9, 2021 11:12
Extract parameters from GET url
Map<String, dynamic> extractParameters(String url){
// get parameters part from complete url string
final paramString = url.substring(url.indexOf('?') + 1);
final params = {};
// iterate over parameter string by splitting it with `&`
paramString.split('&').forEach((String _param) {
// Split each parameter string with `=` to get key & value part
final entry = _param.split('=');
@GAM3RG33K
GAM3RG33K / main.dart
Last active February 7, 2021 05:49
Dart: updating instance's premitive type members
void main() {
final pos = Positions();
print('\n-------------Issue demo---------------\n');
updatePositionIssue(pos.top);
print('positionAttr: ${pos.top}');
updatePositionIssue(pos.left);
print('positionAttr: ${pos.left}');
updatePositionIssue(pos.right);
print('positionAttr: ${pos.right}');
@GAM3RG33K
GAM3RG33K / master_detail_container.dart
Created January 22, 2021 05:25
Master Detail layout
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const masterItemTileUnselectedColor = Color(0xFFECEEF0);
const masterItemTileColor = Color(0xFFFFFFFF);
class MasterDetailContainer extends StatefulWidget {
final Map<EntryTileData, EntryViewData> viewData;
@GAM3RG33K
GAM3RG33K / clickable_text.dart
Created January 22, 2021 05:21
Flutter - Clickable text links
Widget buildClickableTextWithPadding() {
return InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Edit',
@GAM3RG33K
GAM3RG33K / main.dart
Last active July 24, 2020 09:49
[Flutter] Show progress bar based on the response of a method using streams and stream builder
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override