Skip to content

Instantly share code, notes, and snippets.

View rrousselGit's full-sized avatar
🎯
Fluttering

Remi Rousselet rrousselGit

🎯
Fluttering
View GitHub Profile
// Import BenchmarkBase class.
import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:state_notifier/state_notifier.dart';
import 'change_notifier.dart';
class MyChangeNotifier extends ChangeNotifier {
int _value;
int get value => _value;
set value(int value) {
import 'dart:async';
/// This examples starts nested asynchronous operations
/// and cancels _everything_ still pending after 1 second.
///
/// Then, each individual operation can perform custom clean-up
/// inside their `finally` block.
const timeoutDuration = Duration(seconds: 2, milliseconds: 100);
void main() async {
// Iterate only over the first 5 items
await for (final value in counter().take(5)) {
print('$value');
}
}
// Emits an incrementing value every seconds
Stream<int> counter() async* {
print('start');
import 'package:flutter/material.dart';
// This example showcases how, by using functions over classes,
// this _can_ break features such as AnimatedSwitcher
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(context) {
import 'package:flutter/material.dart';
// This example showcases how extracting widgets into StatelessWidgets
// instead of functions can improve performances, by rebuilding
// only what needs to update when the state changes
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
import 'package:flutter/material.dart';
// This example showcases how by using functions instead of StatelessWidgets,
// this can cause bugs when using InheritedWidgets
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(context) {
@rrousselGit
rrousselGit / main.dart
Created July 2, 2020 04:26
reading a family without the key
final todosFamily = ProviderFamily<Todo, int>((ref, id) {
return Todo(
id: '$id',
description: 'Todo $id',
);
});
final currentTodo = Provider<Todo>((ref) => null);
class List extends StatelessWidget {
extension AsValueListenable<T> on Stream<T> {
/// Converts a [Stream] to a [ValueListenable]
///
/// The internal [StreamSubscription] is cancelled when
/// all listeners added to [ValueListenable] are removed.
/// Keep this in mind as this could cause issues with
/// single-subscription streams.
ValueListenable<T> asValueListenable(T initialValue) {
return _StreamValueListenable(this, initialValue);
}
import 'package:flutter/material.dart';
/// A customizable low level widget with some default value
/// Default to have a red background
class SomeBaseWidget extends StatelessWidget {
const SomeBaseWidget({
Key key,
this.color = Colors.red,
this.child,
}) : super(key: key);
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
// Mimicking the behavior of VSyncProvider through a global variable
TickerProvider vsync;