Application runs well when I start it from VC, but when I close it(remove from memory) and try start from phone it blinks with white bg for a second and disappear. On Android devices and iOS simulator it works well. What problem it can be?
Here my code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:prometey_app/models/auth_model.dart';
import 'package:prometey_app/screens/auth/auth_screen.dart';
import 'package:prometey_app/screens/main/main_screen.dart';
import 'package:prometey_app/theme.dart';
import 'package:provider/provider.dart';
import 'controllers/data_manager.dart';
bool isLoggedIn = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await DB.init();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
DB.getUser().then((user) {
print("Get user data from sqlite");
if (user != null) {
print("Try to login with local data");
bitrixAuth(user.email, user.password).then((userResponse) {
if (userResponse.success) {
isLoggedIn = true;
print("Login success");
runApp(MyApp());
} else {
print("Auth data changed");
isLoggedIn = false;
runApp(MyApp());
}
});
} else {
print("No user records in sqlite");
isLoggedIn = false;
runApp(MyApp());
}
});
});
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => AuthModel(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Прометей',
theme: _theme(),
home: isLoggedIn ? MainScreen() : AuthScreen()),
);
}
ThemeData _theme() {
return ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
scaffoldBackgroundColor: Global.bgColor,
buttonTheme: ButtonThemeData(
disabledColor: Global.bgAccent,
buttonColor: Global.bgAccent,
shape: RoundedRectangleBorder(),
textTheme: ButtonTextTheme.normal,
),
);
}
}
Any help would be appreciated!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…