- Flutter app, with provider for dependency management.
- Always run flutter analyze to fix all errors, when there is errors, just run
dart fix --apply
before trying to manipulate the code by yourself - Always ensure your code is fully tested, with flutter test() or widgetTest(), add be generous with goldenTest and screen captures also
- Always prefer type-safe alternative to
dynamic
,late
and other risky behaviors - Do not cast with
as
keyword, but always prefer pattern matching to safely cast and test types - Never use the
dynamic
keyword, norlate
, but preferObject?
which is safer - Always use flutter theme extension to allow UI customization, for every group of UI widgets you build, add a theme extension and refer to hit using context to customize the widgets.
This file contains hidden or 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'; | |
import 'package:provider/provider.dart'; | |
class ServiceBuilder<T extends Service> { | |
final T Function(BuildContext context) create; | |
ServiceBuilder(this.create); | |
Provider<T> asProvider(ValueNotifier<BuildContext> scope) => | |
Provider<T>(create: (_) => create(scope.value)); |
This file contains hidden or 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'; | |
import 'package:provider/provider.dart'; | |
/// Represents a city using a record, with its name (including flag emoji), | |
/// population, and seaside status. | |
/// Records provide automatic equality and hash code implementation. | |
typedef City = ({String name, int population, bool isSeaside}); | |
/// Manages the selection of a city and provides available city data. | |
/// |
This file contains hidden or 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'; | |
import 'package:provider/provider.dart'; | |
/// Data model for the counter, extending ChangeNotifier to notify listeners of changes. | |
class CounterData extends ValueNotifier<int> { | |
CounterData() : super(0); | |
void increment() => value = value + 1; | |
} |
This file contains hidden or 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
/// Attention à TOUJOURS typer le retour des callback/builders | |
/// que vous allez passer aux widgets/controllers. | |
class Foo { | |
Function()? onFoo; | |
void Function()? onFoufou; | |
Foo({ this.onFoo, this.onFoufou }); | |
} | |
void main() { | |
This file contains hidden or 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
/// General demonstration about the annoying way to set to null a copy of another object | |
/// | |
/// @see https://github.com/dart-lang/language/issues/877 | |
/// @see https://stackoverflow.com/questions/68009392/dart-custom-copywith-method-with-nullable-properties | |
class Person { | |
final String name; | |
final String? nickName; | |
Person({required this.name, this.nickName}); |
This file contains hidden or 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:convert'; | |
import 'dart:math'; | |
import 'dart:typed_data'; | |
import 'package:basic_utils/basic_utils.dart'; | |
import 'package:encrypt/encrypt.dart'; | |
// ignore: depend_on_referenced_packages | |
import 'package:crypto/crypto.dart'; | |
import 'package:flutter/foundation.dart' as flutter; | |
import 'package:pointycastle/export.dart'; |
This file contains hidden or 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
// Définition d'une classe scellée pour représenter un résultat | |
// Sealed class : https://dart.dev/language/class-modifiers#sealed | |
sealed class ASealedClass {} | |
// cas 1 | |
class Success extends ASealedClass {} | |
// cas 2 | |
class Failure extends ASealedClass {} | |
/// sous la forme d'un enum | |
enum AnEnum { success, error } |
This file contains hidden or 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() { | |
dynamic myDynamicValue = null; | |
myDynamicValue.length; | |
Object? myTypedValue = myDynamicValue; | |
myTypedValue.length; // that's helpful | |
This file contains hidden or 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
class Generic<T> { | |
final T that; | |
Generic(this.that); | |
} | |
class TypedGeneric<T extends Object> { | |
final T that; | |
TypedGeneric(this.that); | |
} |
NewerOlder