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 { | |
final stream = fn(); | |
print('here'); | |
print(await stream.first); | |
print('done'); | |
} | |
Stream<int> fn() async* { | |
print('try'); |
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 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MaterialApp(home: MyHomePage())); | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key? key}) : 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
import 'package:riverpod/riverpod.dart'; | |
void main() { | |
final container = ProviderContainer(); | |
container.listen<Counter>(counter, (prev, value) { | |
print('count: ${value.count}'); | |
}, fireImmediately: true); | |
container.read(counter).increment(); |
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/foundation.dart'; | |
void main() { | |
print('start'); | |
awaitFn(); | |
thenFn(); | |
print('end'); | |
} | |
Future<void> awaitFn() async { |
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'; | |
Future<void> asyncFunction() async { | |
print('a'); | |
await Future.value(); | |
print('b'); |
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
final firstCounter = ValueNotifier(0); | |
final secondCounter = ValueNotifier(0); | |
class MyApp 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 'observer_list.dart'; | |
typedef VoidCallback = void Function(); | |
class ChangeNotifier { | |
ObserverList<VoidCallback> _listeners = ObserverList<VoidCallback>(); | |
bool get hasListeners { | |
return _listeners.isNotEmpty; | |
} |
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 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 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 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'); |
NewerOlder