Skip to content

Instantly share code, notes, and snippets.

View dumazy's full-sized avatar

Fré Dumazy dumazy

View GitHub Profile
@dumazy
dumazy / main.dart
Created November 8, 2024 09:33
Example of AsyncCache for preventing concurrent execution.
import 'package:async/async.dart';
/// Example of how AsyncCache can prevent concurrent execution.
void main() async {
// Call _execute every second.
// In a real use case, multiple triggers can call [_execute]
// e.g: start up, user interaction, connectivity change, etc
for (int i = 0; i < 10; i++) {
_execute(i);
await Future.delayed(Duration(seconds: 1));
@dumazy
dumazy / main.dart
Created October 23, 2024 17:05
Updating PopScope based on inner Navigator
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@dumazy
dumazy / main.dart
Created August 27, 2024 17:38
ScaffoldMessenger theming issue
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
void showThemedSnackBar() {
final messenger = _scaffoldMessengerKey.currentState!;
@dumazy
dumazy / main.dart
Last active June 6, 2024 19:57
Animated border in a heart shape using PathMetric.getTangentForOffset
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:ui' as ui;
import 'dart:ui';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@dumazy
dumazy / dart-fix-all-separately.sh
Created June 5, 2024 09:56
Apply all 'dart fix' separately
#!/bin/bash
# This script applies Dart fixes to a project and commits the changes for each fix separately.
# It uses the `dart fix --dry-run` command to find the fixes that can be applied.
# For each fix, it applies the fix and commits the changes with a message indicating the fix code.
checkDart() {
if ! command -v dart &> /dev/null
then
echo "Dart could not be found. Please install Dart first."
@dumazy
dumazy / change_notifier_listener_example.dart
Last active March 6, 2024 18:32
A utility to wait for notifyListeners to be called
// When there are external events triggering notifyListeners() in a ChangeNotifier,
// how can we easily test them? Not sure if something like this `ChangeNotifierListener` below
// is a valid approach, or if there are easy ways to test `ChangeNotifier` in a unit test, without a widget test.
// Just for sake of the example
class MyViewModel with ChangeNotifier {
MyViewModel(Stream<Object> eventStream) {
eventStream.listen((event) {
_counter++;
@dumazy
dumazy / main.dart
Created November 26, 2023 12:24
ColorScheme.formSeed
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@dumazy
dumazy / main.dart
Created August 3, 2021 06:08
Complex json display flutter
import 'package:flutter/material.dart';
import 'dart:convert';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 500.0,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: ['English', 'Russian', 'Spanish']
@dumazy
dumazy / gist:b5f64d4c544489569b65be7a30990983
Created October 31, 2020 09:49
Flutter sandbox script
#!/bin/bash
# Absolute path of the Flutter sandbox project
sandbox_path="/Users/fre.dumazy/Developer/Playground/flutter_sandbox"
# Name of Android emulator to open.
# Check with `emulator -list-avds`
avd_name="Pixel_4_API_30"
main() {
processOptions "$@"