Denis Esin
Denis Esin

Reputation: 223

Flutter app won't runs on iOS device after closing

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!

Upvotes: 3

Views: 3527

Answers (1)

fartem
fartem

Reputation: 2541

If you run an app in debug mode, app won't be launched after closing. You need to launch an app in profile or release mode for use it after close. Read more here.

Upvotes: 15

Related Questions