Skip to content

Instantly share code, notes, and snippets.

@yarn-rp
yarn-rp / .dart
Created July 31, 2023 22:33
example using nonConstMyClass version
MyClass nonConstMyClass(int value) => MyClass(value);
void main() {
test('ValueEquality', (){
final a = nonConstMyClass(1);
final b = nonConstMyClass(2);
expect(a, b);
});
}
@yarn-rp
yarn-rp / .dart
Last active July 30, 2023 00:04
testing example using consts and MyClass
void main() {
 test('Value equality', () {
const a = MyClass(1);
const b = MyClass(1);
expect(a, b); // The props is not invoked.
 });
}
@yarn-rp
yarn-rp / .dart
Created July 29, 2023 23:38
Equatable code for overriding == and hashcode
abstract class Equatable {
/// {@macro equatable}
const Equatable();
...
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Equatable &&
runtimeType == other.runtimeType &&
@yarn-rp
yarn-rp / .dart
Created July 29, 2023 23:33
Example of class using Equatable
class MyClass extends Equatable {
const MyClass(this.id);
final int id;
@override
List<Object> get props => [id];
}
class ConstantClass{
const ConstantClass({
required this.arg1,
required this.arg2,
required this.arg3,
});
final int arg1;
final int arg2;
final int arg3;
Widget _kDefaultWidget<T>(T value, BuildContext _) => Text('Error.');
typedef BuilderFunction<T> = Widget Function(T value, BuildContext context);
typedef ListenerFunction<T> = void Function(T value, BuildContext context);
class MatchCase<Q> {
MatchCase(
this.matcher,
this.builder,
class NewIntCaseWidget extends CaseWidget<int> {
NewIntCaseWidget({
super.key,
required int super.value,
}) {
onEquals(0, (value, context) => Text('Value is zero'));
onEquals(1, (value, context) => Text('Value is 1'));
onLessThan(1, (value, context) => Text('Value is less than 1'));
onGreaterThan(1, (value, context) => Text('Value is greater than 1'));
@yarn-rp
yarn-rp / env.dart
Last active October 21, 2022 22:01
import 'package:injectable/injectable.dart';
/// {@template app_environment}
/// Use [AppEnvironment] to provide/access some information about the Environment app is
/// running.
///
/// Access [AppEnvironment] name with the [name] property.
///
/// Currently has supported 3 environments:
/// 1. [AppEnvironment.development] : Use it for develop dependencies. This is
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// InjectableConfigGenerator
// **************************************************************************
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:app_version_config_repository/app_version_config_repository.dart'
as _i7;
import 'package:flutter_boilerplate/domain/app_versioning/service_contracts/app_versioning_service_contract.dart'