首页 > 解决方案 > 应用内更新不适用于封闭测试轨道

问题描述

我已在封闭式测试轨道中发布了我的应用程序。然后我对 UI 进行了更改并在同一轨道上发布了更新,但是当我打开我的应用程序时,我仍然看到旧版本的 UI。当我访问Play商店时,有一个更新按钮。但是,我希望我的应用程序强制更新。我已经等了 9 个小时,但我仍然没有得到更新的版本。

这是我的代码:

 AndroidNotificationChannel channel;
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
 final GlobalKey<NavigatorState> navigatorKey = GlobalKey(debugLabel: "Main Navigator");
 Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    RemoteNotification notification = message.notification;
   flutterLocalNotificationsPlugin.show(
            notification.hashCode,
            notification.title,
            notification.body,
            NotificationDetails(
              android: AndroidNotificationDetails(
                channel.id,
                channel.name,
                channel.description,
                icon: '@drawable/splash',
                playSound: true
              ),
            ));
            navigatorKey.currentState
                      .push(MaterialPageRoute(builder: (_) => OrdersScreen()));
}



Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
    channel = const AndroidNotificationChannel(
      'high_importance_channel', // id
      'High Importance Notifications', // title
      'This channel is used for important notifications.', // description
      importance: Importance.high,
    );
    flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()
        ?.createNotificationChannel(channel);
  await DotEnv.load(fileName: ".env");

 
  
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var _isLoading;
  var appUpdate;
  void initState(){ 
    super.initState();
    checkForUpdate();
    var initializationSettingsAndroid  = AndroidInitializationSettings('@drawable/splash');
    var initializationSettings = InitializationSettings(android:initializationSettingsAndroid);
    flutterLocalNotificationsPlugin.initialize(initializationSettings);
     FirebaseMessaging.instance
        .getInitialMessage()
        .then((RemoteMessage message) {
      if (message != null) {
          navigatorKey.currentState
                       .push(MaterialPageRoute(builder: (_) => OrdersScreen()));
      }
    });
    FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
      print('Inside onmessage'); 
      RemoteNotification notification = message.notification;
      AndroidNotification android = message.notification?.android;
      if (notification != null && android != null) {

        flutterLocalNotificationsPlugin.show(
            notification.hashCode,
            notification.title,
            notification.body,
            NotificationDetails(
              android: AndroidNotificationDetails(
                channel.id,
                channel.name,
                channel.description,
                icon: '@drawable/splash',
                playSound: true
              ),
            ));
     AwesomeDialog(
              context: navigatorKey.currentContext,
              dismissOnTouchOutside:false,
              dialogType: DialogType.SUCCES,
              animType: AnimType.TOPSLIDE,
              title: 'You have received a new order',
              desc: notification.body,      
              btnCancelOnPress: () {
              },
              btnOkText: "Go to Orders",
              btnCancelText:"Cancel",
              btnOkOnPress: () {
                  setState(() {
                  navigatorKey.currentState
                       .push(MaterialPageRoute(builder: (_) => OrdersScreen()));
              });
              }
          )..show();
      }
    });
  }
    

  AppUpdateInfo _updateInfo;
  Future<void> checkForUpdate() async {
  setState(() {
  _isLoading = true;
  });
  InAppUpdate.checkForUpdate().then((info) {
  setState(() {
    _updateInfo = info;
     appUpdate = _updateInfo?.updateAvailable;
      if(appUpdate)
       InAppUpdate.performImmediateUpdate()
                            .catchError((e) => print(e.toString()));
     print('End of app update code');
  });
  
}).catchError((e) => print(e.toString()));

    setState(() {
  _isLoading = false;
  });
}
   
  @override
  Widget build(BuildContext context) {
    var isopen = false; 
    DateTime now = DateTime.now();
      String formattedTime = DateFormat.Hm().format(now);
      print(formattedTime);
      if(formattedTime.toString().compareTo('09:00') >= 0 && formattedTime.toString().compareTo('23:00') <= 0 )
      { 
            print('inside isopen'); 
            isopen = true; 
      }

    return !(_isLoading)?MultiProvider(
      providers: [
       ChangeNotifierProvider(
          create: (_) => Auth(),
        ),
        ChangeNotifierProxyProvider<Auth, Products>(
          create:null,
          update:(ctx,auth, previousProducts) => Products(auth.token, 
          
        auth.userId)), 
         
        ChangeNotifierProvider(
          create: (_) => Cart(),
        ),
        
        ChangeNotifierProvider(
          create: (_) => ColorChanger(),
        ),
    ],

    //The consumer ensures that the material app gets built whenever Auth object changes
        child: Consumer<Auth>(builder: (ctx, auth, _) => 
          MaterialApp( 
        navigatorKey: navigatorKey,    
        title: 'dmd',
        theme: ThemeData(
           textTheme: Theme.of(context).textTheme.apply(
            bodyColor: Colors.black,
            displayColor: Colors.black,
            ),
          primaryColor:  Colors.white,
          accentColor:  Color(0xFFF2AD18),
          fontFamily: 'Muli',
        ),
        home: 
              auth.isAuth?
            
        CategoriesScreen()
         : FutureBuilder(
                      future: auth.tryAutoLogin(),
                      builder: (ctx, authResultSnapshot) =>
                          authResultSnapshot.connectionState ==
                                  ConnectionState.waiting
                              ?  Center(
                                    child: Loading(),
                                )
                              : LoginPage(),
        ),
       // home: PersonalInfoScreen(),
        routes: {
           omeScreen.routeName: (ctx) => NavigationHomeScreen()
        }
      ),
        ) 
    ):Center(child:Loading());
  }
}

标签: flutterdartin-app-update

解决方案


推荐阅读