This file contains 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 Something with ChangeNotifier { | |
bool hasCompletedSomething; | |
} | |
class SomethingElse with ChangeNotifier { | |
bool hasCompletedSomething; | |
} | |
class Loading { | |
Loading(this.value); |
This file contains 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 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; |
This file contains 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
// 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; |
This file contains 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'; | |
/// 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); |
This file contains 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
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); | |
} |
This file contains 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
final todosFamily = ProviderFamily<Todo, int>((ref, id) { | |
return Todo( | |
id: '$id', | |
description: 'Todo $id', | |
); | |
}); | |
final currentTodo = Provider<Todo>((ref) => null); | |
class List extends StatelessWidget { |
This file contains 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'; | |
// 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) { |
This file contains 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'; | |
// 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 |
This file contains 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'; | |
// 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) { |
This file contains 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() 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'); |