forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinherited_notifier.dart
74 lines (64 loc) · 1.79 KB
/
inherited_notifier.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'spin_mode.dart';
/// more information available here:
/// https://api.flutter.dev/flutter/widgets/InheritedNotifier-class.html
class Spinner extends StatelessWidget {
const Spinner({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Transform.rotate(
angle: SpinModel.of(context) * 2.0 * math.pi,
child: Container(
width: 100,
height: 100,
color: Colors.purple,
child: const Center(
child: Text('Whee!', style: TextStyle(color: Colors.white)),
),
),
);
}
}
class MyInheritedNotifier extends StatefulWidget {
const MyInheritedNotifier({Key? key}) : super(key: key);
@override
State<MyInheritedNotifier> createState() => _MyInheritedNotifierState();
}
/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin.
class _MyInheritedNotifierState extends State<MyInheritedNotifier>
with TickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 10),
vsync: this,
)..repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Inherited Notifier')),
body: Center(
child: SpinModel(
notifier: _controller,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Spinner(),
Spinner(),
Spinner(),
],
),
),
),
);
}
}