Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you run app in debug mode, app cannot be launched after closing. Launch app in profile or release mode for usage after dismiss. Read more here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...