forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateful_builder.dart
47 lines (43 loc) · 1.22 KB
/
stateful_builder.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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class MyStatefulBuilder extends StatefulWidget {
const MyStatefulBuilder({Key? key}) : super(key: key);
@override
State<MyStatefulBuilder> createState() => _MyStatefulBuilderState();
}
class _MyStatefulBuilderState extends State<MyStatefulBuilder> {
int counter = 0;
@override
Widget build(BuildContext context) {
///
///
debugPrint('The whole page is built');
return Scaffold(
appBar: AppBar(title: const Text('StatefulBuilder')),
body: Center(
child: StatefulBuilder(
builder: (context, internalState) {
/// this `internalState` is only application inside
/// this bracket
///
debugPrint('StatefulBuilder is built');
return CupertinoButton(
onPressed: () {
internalState(() {
counter++;
});
},
child: Text(
'$counter',
style: const TextStyle(
fontSize: 70,
fontWeight: FontWeight.bold,
),
),
);
},
),
),
);
}
}