I have a flutter app that is building and working perfectly well on both my iOS simulator and my physical iPhone when I run it from Xcode or Android Studio.
Now I published it to the AppStore, and after a couple of users that have downloaded it, the app isn't even starting for them.. it crashes even before reaching the splash screen.
I tried to add Crashlytics in order to catch an error if there's any but nothing was reported.
Did any of you face a similar issue ? Is there a way to understand what's happening ?
Here's my main.dart file:
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:tupitools/core/locator.dart';
import 'package:tupitools/core/models/expansion_torque_search_model.dart';
import 'package:tupitools/core/models/gauge_converter_search_model.dart';
import 'package:tupitools/core/models/gauge_tube_chart_search_model.dart';
import 'package:tupitools/core/models/nominal_pipe_size_search_model.dart';
import 'package:tupitools/core/models/tes2_search_model.dart';
import 'package:tupitools/core/models/tube_expansion_search_model.dart';
import 'package:tupitools/core/theme_service.dart';
import 'package:tupitools/screens/splashscreen.dart';
import 'package:tupitools/utils/sp_utils.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await SPUtil.init();
await ScreenUtil.ensureScreenSize();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
// Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
final themeService = await ThemeService.instance;
var initTheme = themeService.initial;
await setupLocator();
final document = await getApplicationDocumentsDirectory();
await Hive.initFlutter(document.path);
Hive.registerAdapter(GaugeTubeChartSearchModelAdapter());
Hive.registerAdapter(GaugeConverterSearchModelAdapter());
Hive.registerAdapter(NominalPipeSizeSearchModelAdapter());
Hive.registerAdapter(TubeExpansionSearchModelAdapter());
Hive.registerAdapter(ExpansionTorqueSearchModelAdapter());
Hive.registerAdapter(TES2SearchModelAdapter());
if (!SPUtil.containsKey(SPUtil.keyConvertersOrder)) {
SPUtil.setStringList(SPUtil.keyConvertersOrder, ["0", "1", "2", "3", "4", "5"]);
}
if (!SPUtil.containsKey(SPUtil.keyConvertersOrderByName)) {
SPUtil.setStringList(SPUtil.keyConvertersOrderByName,
['Length', 'Weight', 'Circumference to diameter', 'Torque', 'Power', 'Flow rate']);
}
runApp(MyApp(theme: initTheme));
}
class MyApp extends StatelessWidget {
final ThemeData theme;
const MyApp({super.key, required this.theme});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarBrightness: Brightness.dark, // iOS
statusBarIconBrightness: Brightness.dark, // Android
));
final mediaQueryData = MediaQuery.of(context);
final scale = mediaQueryData.textScaleFactor.clamp(1.0, 1.0);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: scale),
child: ScreenUtilInit(
useInheritedMediaQuery: true,
designSize: const Size(393, 852),
minTextAdapt: true,
builder: (context, child) {
return ThemeProvider(
initTheme: theme,
builder: (_, theme) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App name',
theme: theme,
home: child,
);
},
);
},
child: const SplashScreen(),
),
);
}
}
In the end I updated flutter SDK and all the dependencies to the latest version, and everything is working fine since. Not sure what was causing the issue in the first place though ..