forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinherited_widget.dart
55 lines (49 loc) · 1.42 KB
/
inherited_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:flutter/material.dart';
import 'state_widget.dart';
import 'page/counter_page.dart';
class MyInheritedWidget extends StatelessWidget {
const MyInheritedWidget({Key? key}) : super(key: key);
/// this is the [root] file containing `MaterialApp`
///
@override
Widget build(BuildContext context) {
return StateWidget(
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Inherited Widget',
theme: ThemeData(primarySwatch: Colors.purple),
home: const HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final counter = StateInheritedWidget.of(context)!.counter;
return Scaffold(
appBar: AppBar(title: const Text('Inherited Widget')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'$counter',
style: const TextStyle(fontSize: 100),
),
const SizedBox(height: 47),
ElevatedButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const CounterPage(),
),
),
child: const Text('Change Counter'),
),
],
),
),
);
}
}