import 'package:flutter/material.dart';
import 'package:gamershub/Screens/add_amount.dart';
import 'package:gamershub/Screens/home_body.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:gamershub/Screens/splash_screen.dart';
import 'package:gamershub/Screens/wallet.dart';
import 'package:in_app_update/in_app_update.dart';
import 'Screens/login.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
AppUpdateInfo _updateInfo;
bool isLoading = false;
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();
void _showError(dynamic exception) {
_scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Colors.black38,
content: Text(
exception.toString(),
style: TextStyle(
fontSize: 15,
color: Colors.white, fontFamily: "Quicksand", fontWeight: FontWeight.bold,
),
),
duration: Duration(seconds: 3),
));
}
Future<void> checkForUpdate() async {
setState(() {
isLoading = true;
});
InAppUpdate.checkForUpdate().then((info) {
setState(() {
_updateInfo = info;
});
}).catchError((e) => _showError(e));
setState(() {
isLoading = false;
});
}
@override
void initState() {
super.initState();
// checkForUpdate();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.dark,
debugShowCheckedModeBanner: false,
home: isLoading
? Center(
child: SpinKitCircle(
color: Colors.blueGrey.shade900,
size: 50.0,
),
)
: _updateInfo.updateAvailable == true ? Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage("assets/images/bg3.jpg"),fit: BoxFit.cover)
),
child: AlertDialog(
backgroundColor: Colors.blueGrey.shade900,
title: Text("New Update Available! Please Update",
style: TextStyle(fontFamily: "Quicksand", fontWeight: FontWeight.bold,color: Colors.white
),),
actions: [
FlatButton(onPressed: _updateInfo?.updateAvailable == true
? () {
InAppUpdate.performImmediateUpdate().catchError((e) => _showError(e));
}
: null,
child: Text("Update",
style: TextStyle(fontFamily: "Quicksand", fontWeight: FontWeight.bold,color: Colors.white
),))
],
),
) :OnboardingScreen(),
routes: {
'/login': (ctx) => LoginPage(),
'/home': (ctx) => HomeBody(),
'/addamount': (ctx) => AddAmountPage(),
'/wallet': (ctx) => WalletPage(),
},
);
}
}
Я создал проект версии 1.0.0, и мне нужно загрузить его в playstore, и я использовал плагин in_app_update для немедленного обновления приложения, когда я вношу какие-либо изменения в apk и загрузите его в playstore, но. Я завернул домашнюю страницу приложения, чтобы проверить, есть ли первая новая версия, но после горячей перезагрузки я получаю сообщение об ошибке _updateInfo имеет нулевую длину получателя, как это исправить ??
I/flutter (14077): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (14077): The following NoSuchMethodError was thrown building
MyApp(dirty, state: _MyAppState#0dab4):
I/flutter (14077): The getter 'updateAvailable' was called on null.
I/flutter (14077): Receiver: null
I/flutter (14077): Tried calling: updateAvailable
I/flutter (14077):
I/flutter (14077): The relevant error-causing widget was:
I/flutter (14077): MyApp
package:gamershub/main.dart:9
I/flutter (14077):
I/flutter (14077): When the exception was thrown, this was the stack: