Skip to content

Instantly share code, notes, and snippets.

View rrousselGit's full-sized avatar
🎯
Fluttering

Remi Rousselet rrousselGit

🎯
Fluttering
View GitHub Profile
class Something with ChangeNotifier {
bool hasCompletedSomething;
}
class SomethingElse with ChangeNotifier {
bool hasCompletedSomething;
}
class Loading {
Loading(this.value);
class WaitUntilFutureProvider<T> extends SingleChildStatefulWidget {
const WaitUntilFutureProvider({
Key key,
this.waitUntil,
this.create,
Widget child,
}) : super(key: key, child: child);
final bool Function(BuildContext) waitUntil;
final Create<Future<T>> create;
// 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;
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);
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);
}
@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 {
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) {
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 over classes,
// this _can_ break features such as AnimatedSwitcher
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(context) {
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');