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上,当我对apk进行任何更改并上传到playstore上时,我使用插件in_app_update在应用程序中立即更新。我已经包装了应用程序的主页,以检查是否有第一个新版本,但在热重新加载后,我收到一个错误_updateInfo的getter长度为null,如何修复??
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:
您的问题来自以下方面:
: _updateInfo.updateAvailable == true ? Container(
更改为:
:_updateInfo?.updateAvailable != null && _updateInfo.updateAvailable == true ? Container(
好吧,这可能会很晚,但会对其他人有所帮助。
您必须按照以下步骤进行测试。另外请注意,您无法在调试模式下对其进行测试。你必须从playstore下载应用程序并进行测试。
遵循以下内容:
-
确保您的测试设备安装了支持应用内更新的应用程序版本,并且是使用内部应用程序共享URL安装的。
-
按照Play控制台的说明在内部共享您的应用程序。上载应用程序的版本,该版本使用的版本代码高于测试设备上已安装的版本代码。
-
在测试设备上,单击应用程序更新版本的内部应用程序共享链接,但不要从单击链接后出现的Play Store页面安装应用程序。
-
从设备的应用程序抽屉或主屏幕打开应用程序。更新现在应该可用于您的应用程序,您可以测试应用程序内更新的实现。
有关更多信息,请访问此处: