这是CaiYouHui前端,一个关于flutter的安卓app,前端使用flutter实现

splash_screen.dart 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import '../providers/auth_provider.dart';
  4. import '../../core/constants/route_constants.dart';
  5. class SplashScreen extends StatefulWidget {
  6. const SplashScreen({super.key});
  7. @override
  8. SplashScreenState createState() => SplashScreenState();
  9. }
  10. class SplashScreenState extends State<SplashScreen> {
  11. @override
  12. void initState() {
  13. super.initState();
  14. WidgetsBinding.instance.addPostFrameCallback((_) {
  15. _initializeApp();
  16. });
  17. }
  18. Future<void> _initializeApp() async {
  19. final authProvider = Provider.of<AuthProvider>(context, listen: false);
  20. await authProvider.checkAuthStatus();
  21. // 模拟初始化延迟
  22. await Future.delayed(const Duration(milliseconds: 1500));
  23. // 导航到首页
  24. if (mounted) {
  25. Navigator.of(context).pushReplacementNamed(RouteConstants.home);
  26. }
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return Scaffold(
  31. backgroundColor: Colors.blue,
  32. body: Center(
  33. child: Column(
  34. mainAxisAlignment: MainAxisAlignment.center,
  35. children: [
  36. const Icon(
  37. Icons.apps,
  38. size: 100,
  39. color: Colors.white,
  40. ),
  41. const SizedBox(height: 20),
  42. const Text(
  43. '中了么',
  44. style: TextStyle(
  45. fontSize: 32,
  46. fontWeight: FontWeight.bold,
  47. color: Colors.white,
  48. ),
  49. ),
  50. const SizedBox(height: 20),
  51. SizedBox(
  52. width: 60,
  53. height: 60,
  54. child: CircularProgressIndicator(
  55. valueColor: AlwaysStoppedAnimation<Color>(
  56. Color.lerp(Colors.white, Colors.transparent, 0.3)!, // 0.3表示30%透明
  57. ),
  58. strokeWidth: 4,
  59. ),
  60. ),
  61. ],
  62. ),
  63. ),
  64. );
  65. }
  66. }