Flutter hold splash screen for 3 Seconds. How to implement splash screen in Flutter?

前端 未结 9 2020
后悔当初
后悔当初 2021-02-16 00:16

How to show splash screen in flutter for 3 seconds and then go next my login screen.

I have tried.countdowntimer but import is unresolved

import \'pack         


        
9条回答
  •  心在旅途
    2021-02-16 00:37

    This answer is applicable only in case you are using flutter-redux.

    Along with flutter-redux you need to use redux-persist library to show loading screen.

    redux-persist is used to store, rehydrate app state.

    Example:

    1.main.dart

    import 'package:flutter/material.dart';
    import 'package:flutter/foundation.dart';
    import 'package:flutter_redux/flutter_redux.dart';
    import 'package:redux_persist_flutter/redux_persist_flutter.dart';
    
    import 'package:flutter_redux_starter/presentation/platform_adaptive.dart';
    import 'package:flutter_redux_starter/screens/loading_screen.dart';
    import 'package:flutter_redux_starter/store/store.dart';
    import 'package:flutter_redux_starter/middleware/middleware.dart';
    import 'package:flutter_redux_starter/models/app_state.dart';
    import 'package:flutter_redux_starter/routes.dart';
    
    
    void main() => runApp(new MyApp());
    
    class MyApp extends StatelessWidget {
        final store = createStore();
    
        MyApp();
    
        @override
        Widget build(BuildContext context) {
            return new PersistorGate(
                persistor: persistor,
                loading: new LoadingScreen(),
                builder: (context) => new StoreProvider(
                    store: store,
                    child: new MaterialApp(
                        title: 'Flutter test App',
                        theme: defaultTargetPlatform == TargetPlatform.iOS
                            ? kIOSTheme
                            : kDefaultTheme,
                    routes: getRoutes(context, store),
                        initialRoute: '/login',
                    )
                ),
            );
        }
    
    }
    

    2.store.dart

    import 'package:redux/redux.dart';
    
    import 'package:flutter_redux_starter/reducers/app_reducer.dart';
    import 'package:flutter_redux_starter/models/app_state.dart';
    import 'package:flutter_redux_starter/middleware/middleware.dart';
    
    Store createStore() { 
        Store store = new Store(
            appReducer,
            initialState: new AppState(),
            middleware: createMiddleware(),
        );
        persistor.start(store);
    
        return store;
    }
    

    In createStore you can use Future.delayed to delay the creation of store for certain no of seconds.

    new Future.delayed(const Duration(seconds: 3), () {
     // 
    });
    

提交回复
热议问题