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:cloud_firestore/cloud_firestore.dart'; | |
| import 'package:firebase_auth/firebase_auth.dart'; | |
| import 'package:riverpod/riverpod.dart'; | |
| // 1つ目のStreamProvider | |
| final authUserProvider = | |
| StreamProvider<User?>((ref) => FirebaseAuth.instance.userChanges()); | |
| // 2つ目のStreamProvider | |
| // authUserProviderをwatchした値を使ってFirestoreから得られるStreamを返す |
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'; | |
| void main() { | |
| runApp(const App()); | |
| } | |
| class App extends StatelessWidget { | |
| const App({super.key}); | |
| @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'; | |
| void main() => runApp(const App()); | |
| class App extends StatelessWidget { | |
| const App({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return const MaterialApp( |
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'; | |
| import 'package:flutter_test/flutter_test.dart'; | |
| import 'package:rxdart/rxdart.dart'; | |
| void main() { | |
| test('', () async { | |
| // broadcast取ると、expectはtrueになる | |
| // BehaviorSubjectでも、expectはtrueになる | |
| final controller = StreamController<bool>.broadcast(); |
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
| class PackageMetrics extends StateNotifier<AsyncValue<PackageMetricsScore>> { | |
| PackageMetrics(this._ref, {required this.packageName}) | |
| : super(const AsyncLoading()) { | |
| _ref | |
| .watch(pubRepositoryProvider) | |
| .getPackageMetrics(packageName: packageName) | |
| .then((value) => state = AsyncData(value)); | |
| } | |
| final AutoDisposeRef _ref; |
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
| class PackageMetrics | |
| // AutoDispose/Family版のAsyncNotifier | |
| extends AutoDisposeFamilyAsyncNotifier<PackageMetricsScore, String> { | |
| late String _packageName; | |
| @override | |
| Future<PackageMetricsScore> build(String arg) { | |
| _packageName = arg; | |
| return ref | |
| .watch(pubRepositoryProvider) | |
| .getPackageMetrics(packageName: _packageName); |
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'; | |
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
| import 'package:go_router/go_router.dart'; | |
| void main() { | |
| runApp( | |
| const ProviderScope( | |
| child: App(), | |
| ), | |
| ); |
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:quiver/collection.dart'; | |
| void main() { | |
| // maximumSizeのデフォルトは100 | |
| final cache = LruMap<String, int>(maximumSize: 3); | |
| cache['a'] = 1; | |
| print(cache['a']); // 1 | |
| cache['b'] = 2; | |
| print(cache['a']); // 1 |
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
| - json['foo'] as Map<String, dynamic>), | |
| + Map<String, dynamic>.from(json['foo'] as Map)), |
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
| // ignore_for_file: omit_local_variable_types, prefer_final_locals, equal_elements_in_set | |
| import 'dart:collection'; | |
| void main() { | |
| // Setのデフォルト実装は、順番が保たれる LinkedHashSet | |
| Set<String> animals = {'dog', 'dog', 'cat'}; | |
| // 常に[dog, cat] | |
| print(animals.toList()); | |
| Set<String> animals2 = HashSet.of(['dog', 'dog', 'cat']); |