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); | |
} |
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
/// Cast Or provide default value (optional or safely defaulted) | |
/// by the way, "castor" is the french word for beaver... | |
/// ``` | |
/// ___ | |
/// /. .\ | |
/// =\_t_/= | |
/// [|] | |
/// ``` | |
/// | |
extension CastOrExtension<T extends Object> on T { |
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 Cool { | |
final int count; | |
Cool({ int? count = 20 }): this.count = count ?? 20; | |
} | |
class NotCool { | |
final int count; | |
NotCool({ this.count = 20 }); | |
} |
NewerOlder