Skip to content

Instantly share code, notes, and snippets.

View rrousselGit's full-sized avatar
🎯
Fluttering

Remi Rousselet rrousselGit

🎯
Fluttering
View GitHub Profile
void main() async {
final stream = fn();
print('here');
print(await stream.first);
print('done');
}
Stream<int> fn() async* {
print('try');
@rrousselGit
rrousselGit / main.dart
Last active March 6, 2022 14:49
Graph table inspector
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);
@rrousselGit
rrousselGit / main.dart
Last active January 15, 2022 12:18
raw Riverpod
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();
import 'package:flutter/foundation.dart';
void main() {
print('start');
awaitFn();
thenFn();
print('end');
}
Future<void> awaitFn() async {
// 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');
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
final firstCounter = ValueNotifier(0);
final secondCounter = ValueNotifier(0);
class MyApp extends StatelessWidget {
@rrousselGit
rrousselGit / change_notifier.dart
Last active August 1, 2020 05:43
A benchmark that compares before and after performances for notifyListeners of ChangeNotifier
import 'observer_list.dart';
typedef VoidCallback = void Function();
class ChangeNotifier {
ObserverList<VoidCallback> _listeners = ObserverList<VoidCallback>();
bool get hasListeners {
return _listeners.isNotEmpty;
}
// 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');