@@ -16,39 +16,64 @@ import 'unit_paint.dart';
1616/// 说明: app 闪屏页
1717
1818class UnitSplash extends StatefulWidget {
19+ const UnitSplash ();
20+
1921 @override
2022 _UnitSplashState createState () => _UnitSplashState ();
2123}
2224
2325class _UnitSplashState extends State <UnitSplash > with TickerProviderStateMixin {
24- late AnimationController _controller;
26+ late AnimationController _controller;
2527
2628 ValueNotifier <bool > _animEnd = ValueNotifier <bool >(false );
2729
2830 final Duration animTime = const Duration (milliseconds: 1000 );
2931 final Duration delayTime = const Duration (milliseconds: 500 );
3032 final Duration fadeInTime = const Duration (milliseconds: 600 );
3133
34+ late Animation <Offset > logoOffsetAnim;
35+ late Animation <Offset > headOffsetAnim;
36+ late Animation <double > logoScaleAnim;
37+
38+ late UnitPainter unitPainter = UnitPainter (repaint: _controller);
39+
3240 @override
3341 void initState () {
3442 super .initState ();
3543
36- SystemUiOverlayStyle systemUiOverlayStyle =
37- const SystemUiOverlayStyle (statusBarColor: Colors .transparent);
38- SystemChrome .setSystemUIOverlayStyle (systemUiOverlayStyle);
44+ SystemChrome .setSystemUIOverlayStyle (
45+ const SystemUiOverlayStyle (
46+ statusBarColor: Colors .transparent,
47+ ),
48+ );
3949
4050 _controller = AnimationController (duration: animTime, vsync: this )
4151 ..addStatusListener (_listenStatus)
4252 ..forward ();
4353
44- Future .delayed (delayTime).then ((e) {
45- _animEnd.value = true ;
46- });
54+ initAnimation ();
55+
56+ Future .delayed (delayTime).then ((e) => _animEnd.value = true );
57+ }
58+
59+ void initAnimation () {
60+ logoOffsetAnim = Tween <Offset >(
61+ begin: const Offset (0 , 0 ),
62+ end: const Offset (0 , - 1.5 ),
63+ ).animate (_controller);
64+
65+ headOffsetAnim = Tween <Offset >(
66+ end: const Offset (0 , 0 ),
67+ begin: const Offset (0 , - 5 ),
68+ ).animate (_controller);
69+
70+ logoScaleAnim = Tween (begin: 2.0 , end: 1.0 ).animate (_controller);
4771 }
4872
4973 @override
5074 void dispose () {
5175 _controller.dispose ();
76+ _animEnd.dispose ();
5277 super .dispose ();
5378 }
5479
@@ -62,61 +87,52 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
6287
6388 @override
6489 Widget build (BuildContext context) {
65- final double winH = MediaQuery .of (context).size.height;
66- final double winW = MediaQuery .of (context).size.width;
67-
68- return BlocListener <GlobalBloc , GlobalState >(
69- listener: _listenStart,
70- child: Scaffold (
71- body: Stack (
90+ final Size winSize = MediaQuery .of (context).size;
91+ return Material (
92+ child: BlocListener <GlobalBloc , GlobalState >(
93+ listener: _listenStart,
94+ child: Stack (
7295 alignment: Alignment .center,
7396 children: < Widget > [
7497 _buildFlutterLogo (),
75- Container (
76- width: winW,
77- height: winH,
78- child: CustomPaint (
79- painter: UnitPainter (repaint: _controller),
80- ),
98+ CustomPaint (
99+ painter: unitPainter,
100+ size: winSize,
81101 ),
82- _buildFlutterUnitText (winH, winW ),
102+ _buildFlutterUnitText (winSize.height, winSize.width ),
83103 _buildHead (),
84- Positioned (bottom: 15 , child: SplashBottom ())
104+ const Positioned (bottom: 15 , child: SplashBottom ())
85105 ],
86106 ),
87107 ),
88108 );
89109 }
90110
91111 Widget _buildFlutterUnitText (double winH, double winW) {
92-
93112 return Positioned (
94113 top: winH / 1.4 ,
95114 child: ValueListenableBuilder (
115+ child: FlutterUnitText (
116+ text: StrUnit .appName,
117+ color: Theme .of (context).primaryColor,
118+ ),
96119 valueListenable: _animEnd,
97- builder: (_,bool value, __) => value
98- ? FlutterUnitText (
99- text: StrUnit .appName,
100- color: Theme .of (context).primaryColor,
101- )
102- : SizedBox (),
120+ builder: (_, bool value, Widget ? child) => value
121+ ? child! : const SizedBox (),
103122 ),
104123 );
105124 }
106125
107126 Widget _buildFlutterLogo () {
108127 return SlideTransition (
109- position: Tween <Offset >(
110- begin: const Offset (0 , 0 ),
111- end: const Offset (0 , - 1.5 ),
112- ).animate (_controller),
128+ position: logoOffsetAnim,
113129 child: RotationTransition (
114130 turns: _controller,
115131 child: ScaleTransition (
116- scale: Tween (begin : 2.0 , end : 1.0 ). animate (_controller) ,
132+ scale: logoScaleAnim ,
117133 child: FadeTransition (
118134 opacity: _controller,
119- child: Container (
135+ child: SizedBox (
120136 height: 120 ,
121137 child: const FlutterLogo (
122138 size: 60 ,
@@ -127,20 +143,18 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
127143 }
128144
129145 Widget _buildHead () => SlideTransition (
130- position: Tween <Offset >(
131- end: const Offset (0 , 0 ),
132- begin: const Offset (0 , - 5 ),
133- ).animate (_controller),
134- child: Container (
135- height: 45 ,
136- width: 45 ,
137- child: Image .asset ('assets/images/icon_head.webp' ),
138- ));
146+ position: headOffsetAnim,
147+ child: Image .asset (
148+ 'assets/images/icon_head.webp' ,
149+ width: 45 ,
150+ height: 45 ,
151+ ),
152+ );
139153
140154 // 监听资源加载完毕,启动,触发事件
141155 void _listenStart (BuildContext context, GlobalState state) {
142- BlocProvider .of <WidgetsBloc >(context).add (EventTabTap (WidgetFamily .statelessWidget));
143- BlocProvider .of <LikeWidgetBloc >(context).add (EventLoadLikeData ());
144- BlocProvider .of <CategoryBloc >(context).add (EventLoadCategory ());
156+ BlocProvider .of <WidgetsBloc >(context).add (const EventTabTap (WidgetFamily .statelessWidget));
157+ BlocProvider .of <LikeWidgetBloc >(context).add (const EventLoadLikeData ());
158+ BlocProvider .of <CategoryBloc >(context).add (const EventLoadCategory ());
145159 }
146160}
0 commit comments