Spaces:
Runtime error
Runtime error
| import 'package:flutter/material.dart'; | |
| import 'package:after_layout/after_layout.dart'; | |
| import 'package:shared_preferences/shared_preferences.dart'; | |
| // import 'lobby_screen.dart'; | |
| import 'setup_screen.dart'; | |
| import 'home_screen.dart'; | |
| import 'loading.dart'; | |
| void main() { | |
| runApp(const MainApp()); | |
| } | |
| class MainApp extends StatelessWidget { | |
| const MainApp({super.key}); | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title:'HapticLink', | |
| debugShowCheckedModeBanner: false, | |
| theme:ThemeData.dark(), | |
| // home: SetupScreen(), | |
| // home: Loading(), | |
| home: const Splash(), | |
| ); | |
| } | |
| } | |
| class Splash extends StatefulWidget { | |
| const Splash({super.key}); | |
| State<Splash> createState(){ | |
| return SplashState(); | |
| } | |
| } | |
| class SplashState extends State<Splash> with AfterLayoutMixin<Splash>{ | |
| void checkFirstScreen() async{ | |
| SharedPreferences prefs = await SharedPreferences.getInstance(); | |
| // if prefs:"setup_done" not set | |
| if(prefs.getBool('setup_done')==null){ | |
| // go to Setup Screen | |
| Navigator.pushReplacement( | |
| context, | |
| MaterialPageRoute( | |
| builder: (context)=>SetupScreen() | |
| ) | |
| ); | |
| } | |
| else{ | |
| // go to lobby Screen directly | |
| Navigator.pushReplacement( | |
| context, | |
| MaterialPageRoute( | |
| // builder: (context)=>LobbyScreen() | |
| builder: (context)=>HomeScreen() | |
| ) | |
| ); | |
| } | |
| } | |
| void afterFirstLayout(BuildContext context){ | |
| checkFirstScreen(); | |
| } | |
| Widget build(BuildContext context){ | |
| return const Loading(); | |
| } | |
| } | |