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

splash_screen.dart 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. _initializeApp();
  15. }
  16. Future<void> _initializeApp() async {
  17. final authProvider = Provider.of<AuthProvider>(context, listen: false);
  18. await authProvider.checkAuthStatus();
  19. // 模拟初始化延迟
  20. await Future.delayed(const Duration(milliseconds: 1500));
  21. // 导航到首页
  22. if (mounted) {
  23. Navigator.of(context).pushReplacementNamed(RouteConstants.home);
  24. }
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. backgroundColor: Colors.blue,
  30. body: Center(
  31. child: Column(
  32. mainAxisAlignment: MainAxisAlignment.center,
  33. children: [
  34. const Icon(
  35. Icons.apps,
  36. size: 100,
  37. color: Colors.white,
  38. ),
  39. const SizedBox(height: 20),
  40. const Text(
  41. '采油会',
  42. style: TextStyle(
  43. fontSize: 32,
  44. fontWeight: FontWeight.bold,
  45. color: Colors.white,
  46. ),
  47. ),
  48. const SizedBox(height: 20),
  49. SizedBox(
  50. width: 60,
  51. height: 60,
  52. child: CircularProgressIndicator(
  53. valueColor: AlwaysStoppedAnimation<Color>(
  54. Color.lerp(Colors.white, Colors.transparent, 0.3)!, // 0.3表示30%透明
  55. ),
  56. strokeWidth: 4,
  57. ),
  58. ),
  59. ],
  60. ),
  61. ),
  62. );
  63. }
  64. }