Skip to content

Instantly share code, notes, and snippets.

@chooyan-eng
Last active February 15, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chooyan-eng/f6d0042cfaba5f08c78bacda43d32875 to your computer and use it in GitHub Desktop.
Save chooyan-eng/f6d0042cfaba5f08c78bacda43d32875 to your computer and use it in GitHub Desktop.
Sample for Flutter Tokyo
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() => runApp(
const ProviderScope(
child: MyApp(),
),
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Meetup'),
);
}
}
final countProvider = StateProvider((ref) {
return 0;
});
class MyHomePage extends ConsumerWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
'You have pushed the button this many times:',
),
_CounterText(),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
ref.read(countProvider.notifier).state += 1;
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class _CounterText extends ConsumerWidget {
const _CounterText();
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(countProvider);
return Text(
'$count',
style: Theme.of(context).textTheme.headlineMedium,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment