I'm having a complex issue with my app using Flutter

52 Views Asked by At

I'm having an issue with my app written with Flutter, specifically related to SharedPreferences configuration. The issue is seen when running the app in release mode, where I am greeted by a white screen or sometimes a splash page with no ability to navigate or interact. The app works fine in debug mode though. I added some Kotlin code for sending and setting local notifications, after which the issue came into existence.

What's even more confusing is that the debug mode doesn't show any significant errors, making it difficult to pinpoint the source of the issue. I can share more code if needed.

import 'package:al_muezzin/bindings/initialbindings.dart';
import 'package:al_muezzin/core/constant/color.dart';
import 'package:al_muezzin/core/localization/translation.dart';
import 'package:al_muezzin/core/service/services.dart';
import 'package:al_muezzin/route.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:timeago/timeago.dart' as timeago;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initialServices();
  timeago.setLocaleMessages('ar', timeago.ArMessages());
  runApp(const MyApp());
}

final MethodChannel _channel = MethodChannel('com.example.al_muezzin/AlarmManagement');

Future<void> setNextAlarm() async {
  try {
    await _channel.invokeMethod('setNextAlarm');
  } on PlatformException catch (e) {
    Fluttertoast.showToast(msg: 'Failed to set alarm: ${e.message}');
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        fontFamily: 'AL-JAZEERA',
        appBarTheme: AppBarTheme(
          backgroundColor: AppColor.secondColor
        ),
        scaffoldBackgroundColor: Color(0xffF2F2F2),
      ),
      locale: Locale('ar'),
      translations: MyTranslation(),
      initialBinding: InitialBindings(),
      getPages: getPages,
    );
  }
}

import 'package:al_muezzin/core/function/print.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MyServices extends GetxService {
  late SharedPreferences sharedPreferences;

  Future<MyServices> init() async {
    sharedPreferences = await SharedPreferences.getInstance();
    return this;
  }
}

initialServices() async {
  await Get.putAsync(() => MyServices().init());
}

When I uninitialize the services, the app works, but with an experimental interface, because my whole app depends on this service

0

There are 0 best solutions below