<aside> 💡 교재 12장 정리해서 강의하기 (창고, 창고데이터, 창고관리자)
</aside>
import 'package:demo3/num_provider.dart';
import 'package:demo3/num_sn_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.yellow,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Expanded(child: HeaderPage()),
Expanded(child: CenterPage()),
Expanded(child: BottomPage()),
],
),
),
);
}
}
class HeaderPage extends ConsumerWidget {
HeaderPage();
@override
Widget build(BuildContext context, WidgetRef ref) {
int num = ref.watch(numSNProvider);
return Container(
color: Colors.red,
child: Align(
child: Text(
"${num}",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 100,
decoration: TextDecoration.none),
),
),
);
}
}
class CenterPage extends ConsumerWidget {
CenterPage();
@override
Widget build(BuildContext context, WidgetRef ref) {
int num = ref.read(numProvider);
return Container(
color: Colors.green,
child: Align(
child: Text(
"${num}",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 100,
decoration: TextDecoration.none),
),
),
);
}
}
class BottomPage extends ConsumerWidget {
BottomPage();
@override
Widget build(BuildContext context, WidgetRef ref) {
return Container(
color: Colors.blue,
child: Align(
child: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () {
NumStore ns = ref.read(numSNProvider.notifier);
ns.state++;
},
child: Text(
"증가",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 100,
),
),
),
),
);
}
}