dart最新2024.06.17
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( title: 'Flutter Demo', home: SplashScreen(), ); } } class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @override // ignore: library_private_types_in_public_api _SplashScreenState createState() => _SplashScreenState(); } class _SplashScreenState extends State<SplashScreen> { @override Widget build(BuildContext context) { return FutureBuilder( future: _navigateToHome(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Container(); // 闪屏完成后,返回一个空容器 } else { return Scaffold( body: Image.asset('assets/images/splash360.png'), ); } }, ); } Future<void> _navigateToHome() async { await Future.delayed(const Duration(seconds: 2)); // 假设的初始化时间 // ignore: use_build_context_synchronously Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (context) => const HomePage())); } } class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: const Center( child: Text('地图自己当前位置'), ), bottomNavigationBar: BottomNavigationBar( items: const [ BottomNavigationBarItem(icon: Icon(Icons.category), label: '收货'), BottomNavigationBarItem(icon: Icon(Icons.email), label: '记录'), //BottomNavigationBarItem(icon: Icon(Icons.label), label: '位置'), BottomNavigationBarItem(icon: Icon(Icons.settings), label: '自己'), ], ), ); } }