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 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) { |
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: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); |
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() 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'); |
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'; | |
| // 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 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'; | |
| // 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 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'; | |
| // 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 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
| 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 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
| 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 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'; | |
| /// 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 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
| // 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; |