forked from lxm_flutter/FlutterUnit
优化闪屏页
This commit is contained in:
@@ -1,29 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_unit/model/category_model.dart';
|
||||
import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/views/pages/app/unit_navigation.dart';
|
||||
import 'package:flutter_unit/views/pages/about/about_me_page.dart';
|
||||
import 'package:flutter_unit/user_system/pages/login/login_page.dart';
|
||||
import 'package:flutter_unit/user_system/pages/register/register_page.dart';
|
||||
import 'package:flutter_unit/views/pages/about/about_app_page.dart';
|
||||
import 'package:flutter_unit/views/pages/about/about_me_page.dart';
|
||||
import 'package:flutter_unit/views/pages/about/version_info.dart';
|
||||
import 'package:flutter_unit/views/pages/app/unit_navigation.dart';
|
||||
import 'package:flutter_unit/views/pages/category/category_detail.dart';
|
||||
import 'package:flutter_unit/views/pages/category/collect_page.dart';
|
||||
import 'package:flutter_unit/views/pages/data_manage/data_manage_page.dart';
|
||||
import 'package:flutter_unit/views/pages/gallery/gallery_page.dart';
|
||||
import 'package:flutter_unit/views/pages/issues_point/issues_detail.dart';
|
||||
import 'package:flutter_unit/views/pages/issues_point/issues_point_page.dart';
|
||||
import 'package:flutter_unit/user_system/pages/login/login_page.dart';
|
||||
import 'package:flutter_unit/user_system/pages/register/register_page.dart';
|
||||
import 'package:flutter_unit/views/pages/search/serach_page.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/code_style_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/font_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/item_style_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/setting_page.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/theme_color_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/attr_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/point_unit_page.dart';
|
||||
|
||||
import 'package:flutter_unit/views/pages/widget_detail/widget_detail_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/layout_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/setting_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/point_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/widget_detail/widget_detail_page.dart';
|
||||
|
||||
import 'router_utils.dart';
|
||||
|
||||
@@ -63,7 +62,7 @@ class UnitRouter {
|
||||
switch (settings.name) {
|
||||
//
|
||||
case nav:
|
||||
return Left2RightRouter(child: UnitNavigation());
|
||||
return Left2RightRouter(child: const UnitNavigation());
|
||||
|
||||
// 组件详情页
|
||||
case widget_detail:
|
||||
|
||||
@@ -4,16 +4,20 @@ import 'package:equatable/equatable.dart';
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
abstract class LikeWidgetEvent extends Equatable {}
|
||||
abstract class LikeWidgetEvent extends Equatable {
|
||||
const LikeWidgetEvent();
|
||||
}
|
||||
|
||||
class EventLoadLikeData extends LikeWidgetEvent {
|
||||
const EventLoadLikeData();
|
||||
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ToggleLikeWidgetEvent extends LikeWidgetEvent {
|
||||
final int id;
|
||||
|
||||
ToggleLikeWidgetEvent({required this.id});
|
||||
const ToggleLikeWidgetEvent({required this.id});
|
||||
|
||||
@override
|
||||
// TODO: implement props
|
||||
@@ -21,6 +25,8 @@ class ToggleLikeWidgetEvent extends LikeWidgetEvent {
|
||||
}
|
||||
|
||||
class LoadCollectEvent extends LikeWidgetEvent {
|
||||
const LoadCollectEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ abstract class WidgetsEvent extends Equatable {
|
||||
class EventTabTap extends WidgetsEvent {
|
||||
final WidgetFamily family;
|
||||
|
||||
EventTabTap(this.family);
|
||||
const EventTabTap(this.family);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,19 +13,18 @@ import 'package:flutter_unit/views/pages/splash/unit_splash.dart';
|
||||
class FlutterUnit extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<GlobalBloc, GlobalState>(builder: (_, state) {
|
||||
return MaterialApp(
|
||||
showPerformanceOverlay: state.showPerformanceOverlay,
|
||||
title: StrUnit.appName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
onGenerateRoute: UnitRouter.generateRoute,
|
||||
theme: ThemeData(
|
||||
primarySwatch: state.themeColor,
|
||||
fontFamily: state.fontFamily,
|
||||
),
|
||||
home: UnitSplash(),
|
||||
);
|
||||
});
|
||||
return BlocBuilder<GlobalBloc, GlobalState>(
|
||||
builder: (_, state) => MaterialApp(
|
||||
showPerformanceOverlay: state.showPerformanceOverlay,
|
||||
title: StrUnit.appName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
onGenerateRoute: UnitRouter.generateRoute,
|
||||
theme: ThemeData(
|
||||
primarySwatch: state.themeColor,
|
||||
fontFamily: state.fontFamily,
|
||||
),
|
||||
home: const UnitSplash(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import 'package:flutter_unit/views/pages/widget_home/home_page.dart';
|
||||
|
||||
|
||||
class UnitNavigation extends StatefulWidget {
|
||||
const UnitNavigation();
|
||||
|
||||
@override
|
||||
_UnitNavigationState createState() => _UnitNavigationState();
|
||||
}
|
||||
@@ -26,7 +28,7 @@ class _UnitNavigationState extends State<UnitNavigation> {
|
||||
final PageController _controller = PageController();
|
||||
|
||||
// 禁止 PageView 滑动
|
||||
final ScrollPhysics neverScroll = const NeverScrollableScrollPhysics();
|
||||
final ScrollPhysics _neverScroll = const NeverScrollableScrollPhysics();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -45,7 +47,7 @@ class _UnitNavigationState extends State<UnitNavigation> {
|
||||
floatingActionButton: _buildSearchButton(context),
|
||||
body: wrapOverlayTool(
|
||||
child: PageView(
|
||||
physics: neverScroll,
|
||||
physics: _neverScroll,
|
||||
controller: _controller,
|
||||
children: <Widget>[
|
||||
HomePage(),
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_unit/app/res/style/unit_text_style.dart';
|
||||
|
||||
class SplashBottom extends StatefulWidget {
|
||||
const SplashBottom();
|
||||
|
||||
@override
|
||||
_SplashBottomState createState() => _SplashBottomState();
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@ import 'unit_paint.dart';
|
||||
/// 说明: app 闪屏页
|
||||
|
||||
class UnitSplash extends StatefulWidget {
|
||||
const UnitSplash();
|
||||
|
||||
@override
|
||||
_UnitSplashState createState() => _UnitSplashState();
|
||||
}
|
||||
|
||||
class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late AnimationController _controller;
|
||||
|
||||
ValueNotifier<bool> _animEnd = ValueNotifier<bool>(false);
|
||||
|
||||
@@ -29,26 +31,49 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
|
||||
final Duration delayTime = const Duration(milliseconds: 500);
|
||||
final Duration fadeInTime = const Duration(milliseconds: 600);
|
||||
|
||||
late Animation<Offset> logoOffsetAnim;
|
||||
late Animation<Offset> headOffsetAnim;
|
||||
late Animation<double> logoScaleAnim;
|
||||
|
||||
late UnitPainter unitPainter = UnitPainter(repaint: _controller);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
SystemUiOverlayStyle systemUiOverlayStyle =
|
||||
const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
||||
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
),
|
||||
);
|
||||
|
||||
_controller = AnimationController(duration: animTime, vsync: this)
|
||||
..addStatusListener(_listenStatus)
|
||||
..forward();
|
||||
|
||||
Future.delayed(delayTime).then((e) {
|
||||
_animEnd.value = true;
|
||||
});
|
||||
initAnimation();
|
||||
|
||||
Future.delayed(delayTime).then((e) => _animEnd.value = true);
|
||||
}
|
||||
|
||||
void initAnimation() {
|
||||
logoOffsetAnim = Tween<Offset>(
|
||||
begin: const Offset(0, 0),
|
||||
end: const Offset(0, -1.5),
|
||||
).animate(_controller);
|
||||
|
||||
headOffsetAnim = Tween<Offset>(
|
||||
end: const Offset(0, 0),
|
||||
begin: const Offset(0, -5),
|
||||
).animate(_controller);
|
||||
|
||||
logoScaleAnim = Tween(begin: 2.0, end: 1.0).animate(_controller);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_animEnd.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -62,26 +87,21 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double winH = MediaQuery.of(context).size.height;
|
||||
final double winW = MediaQuery.of(context).size.width;
|
||||
|
||||
return BlocListener<GlobalBloc, GlobalState>(
|
||||
listener: _listenStart,
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
final Size winSize = MediaQuery.of(context).size;
|
||||
return Material(
|
||||
child: BlocListener<GlobalBloc, GlobalState>(
|
||||
listener: _listenStart,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
_buildFlutterLogo(),
|
||||
Container(
|
||||
width: winW,
|
||||
height: winH,
|
||||
child: CustomPaint(
|
||||
painter: UnitPainter(repaint: _controller),
|
||||
),
|
||||
CustomPaint(
|
||||
painter: unitPainter,
|
||||
size: winSize,
|
||||
),
|
||||
_buildFlutterUnitText(winH, winW),
|
||||
_buildFlutterUnitText(winSize.height, winSize.width),
|
||||
_buildHead(),
|
||||
Positioned(bottom: 15, child: SplashBottom())
|
||||
const Positioned(bottom: 15, child: SplashBottom())
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -89,34 +109,30 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
Widget _buildFlutterUnitText(double winH, double winW) {
|
||||
|
||||
return Positioned(
|
||||
top: winH / 1.4,
|
||||
child: ValueListenableBuilder(
|
||||
child: FlutterUnitText(
|
||||
text: StrUnit.appName,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
valueListenable: _animEnd,
|
||||
builder: (_,bool value, __) => value
|
||||
? FlutterUnitText(
|
||||
text: StrUnit.appName,
|
||||
color: Theme.of(context).primaryColor,
|
||||
)
|
||||
: SizedBox(),
|
||||
builder: (_, bool value, Widget? child) => value
|
||||
? child! : const SizedBox(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFlutterLogo() {
|
||||
return SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0, 0),
|
||||
end: const Offset(0, -1.5),
|
||||
).animate(_controller),
|
||||
position: logoOffsetAnim,
|
||||
child: RotationTransition(
|
||||
turns: _controller,
|
||||
child: ScaleTransition(
|
||||
scale: Tween(begin: 2.0, end: 1.0).animate(_controller),
|
||||
scale: logoScaleAnim,
|
||||
child: FadeTransition(
|
||||
opacity: _controller,
|
||||
child: Container(
|
||||
child: SizedBox(
|
||||
height: 120,
|
||||
child: const FlutterLogo(
|
||||
size: 60,
|
||||
@@ -127,20 +143,18 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
Widget _buildHead() => SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
end: const Offset(0, 0),
|
||||
begin: const Offset(0, -5),
|
||||
).animate(_controller),
|
||||
child: Container(
|
||||
height: 45,
|
||||
width: 45,
|
||||
child: Image.asset('assets/images/icon_head.webp'),
|
||||
));
|
||||
position: headOffsetAnim,
|
||||
child: Image.asset(
|
||||
'assets/images/icon_head.webp',
|
||||
width: 45,
|
||||
height: 45,
|
||||
),
|
||||
);
|
||||
|
||||
// 监听资源加载完毕,启动,触发事件
|
||||
void _listenStart(BuildContext context, GlobalState state) {
|
||||
BlocProvider.of<WidgetsBloc>(context).add(EventTabTap(WidgetFamily.statelessWidget));
|
||||
BlocProvider.of<LikeWidgetBloc>(context).add(EventLoadLikeData());
|
||||
BlocProvider.of<CategoryBloc>(context).add(EventLoadCategory());
|
||||
BlocProvider.of<WidgetsBloc>(context).add(const EventTabTap(WidgetFamily.statelessWidget));
|
||||
BlocProvider.of<LikeWidgetBloc>(context).add(const EventLoadLikeData());
|
||||
BlocProvider.of<CategoryBloc>(context).add(const EventLoadCategory());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user