Created with <3 with dartpad.dev.
Created
November 1, 2023 17:55
-
-
Save chimon2000/512de83e0586d359b98aa98671998e17 to your computer and use it in GitHub Desktop.
tangled-marble-2871
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'; | |
import 'dart:async'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
final testStreamProvider = StreamProvider<int>((ref) { | |
return Stream.periodic(const Duration(seconds: 2), (count) { | |
return count; | |
}); | |
}); | |
class TestNotifier extends AsyncNotifier<int> { | |
@override | |
FutureOr<int> build() { | |
return ref.watch(testStreamProvider.future); | |
} | |
} | |
final testProvider = AsyncNotifierProvider<TestNotifier, int>(TestNotifier.new); | |
void main() { | |
runApp(const ProviderScope(child: MyApp())); | |
} | |
class MyApp extends ConsumerWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context, WidgetRef ref) { | |
ref.listen(testProvider, (prev, curr) => print(curr)); | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
useMaterial3: true, | |
iconButtonTheme: IconButtonThemeData( | |
style: IconButton.styleFrom( | |
hoverColor: Colors.transparent, | |
focusColor: Colors.transparent, | |
highlightColor: Colors.transparent, | |
), | |
), | |
), | |
debugShowCheckedModeBanner: false, | |
home: const Scaffold( | |
body: Center( | |
child: Text('Some text'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment