flutter - Flutter:发布后应用程序无法登录,并且 floatingActionButton 不起作用
问题描述
我的应用类似于 Udemy 应用,它是由 Flutter 开发的
我已将 iOS 版本发布到 App Store 并且运行良好,但在 Android Studio 中却遇到了奇怪的情况......
当我在模拟器或连接到 Android Studio 的真实设备上运行应用程序时,一切正常,但是当使用命令运行它时
Flutter run --release
或构建apk文件或abb文件下图中显示的带有Whatsapp图标的凸起按钮不起作用
当用户尝试登录时,签名页面中的大问题 [代码如下所示] 我收到此 HTTP 尝试获取错误消息
MissingPluginException(在通道 plugins.flutter.io/shared_preferences 上找不到方法 getAll 的实现
注意:我在下面显示的代码中使用单词(errrrrrrrrrrrrrooooor)来显示错误消息的显示位置
在搜索此错误后,我发现当共享首选项中没有以前的值时我们收到此错误,但在应用程序中首次使用签名前我不使用共享首选项
所以,我不明白为什么会发生这种情况,特别是在 apk 版本中,并且在模拟器或真实设备上的测试模式下运行良好
注意:我在清单文件中添加了 Internet 权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
所以,我需要帮助
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:connect/models/app_logo.dart';
import 'package:connect/widgets/app_bar_two.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import '../models/common_functions.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth.dart';
import '../models/http_exception.dart';
import '../constants.dart';
enum AuthMode { Signup, Login }
class AuthScreen extends StatefulWidget {
static const routeName = '/auth';
@override
_AuthScreenState createState() => _AuthScreenState();
}
class _AuthScreenState extends State<AuthScreen> {
final _controller = StreamController<AppLogo>();
final searchController = TextEditingController();
fetchMyLogo() async {
var url = BASE_URL +'/api/app_logo';
try {
final response = await http.get(url);
print(response.body);
if (response.statusCode == 200) {
var logo = AppLogo.fromJson(jsonDecode(response.body));
_controller.add(logo);
}
// print(extractedData);
} catch (error) {
throw (error);
}
}
void initState() {
super.initState();
this.fetchMyLogo();
}
@override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;
// final transformConfig = Matrix4.rotationZ(-8 * pi / 180);
// transformConfig.translate(-10.0);
return Scaffold(
appBar: CustomAppBarTwo(),
// resizeToAvoidBottomInset: false,
body: Stack(
children: <Widget>[
SingleChildScrollView(
child: Container(
height: deviceSize.height,
width: deviceSize.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: StreamBuilder<AppLogo>(
stream: _controller.stream,
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Container();
} else {
if (snapshot.error != null) {
return Text("Error Occured");
} else {
// saveImageUrlToSharedPref(snapshot.data.darkLogo);
return CachedNetworkImage(
imageUrl: snapshot.data.favicon,
fit: BoxFit.contain,
height: 33,
);
}
}
},
),
),
Container(
margin: EdgeInsets.only(bottom: 20.0),
padding:
EdgeInsets.symmetric(vertical: 4.0, horizontal: 94.0),
child: Text(
'Login',
style: TextStyle(
color: kTextColor,
fontSize: 30,
fontWeight: FontWeight.normal,
),
),
),
Flexible(
flex: deviceSize.width > 600 ? 2 : 1,
child: AuthCard(),
),
],
),
),
),
],
),
);
}
}
class AuthCard extends StatefulWidget {
const AuthCard({
Key key,
}) : super(key: key);
@override
_AuthCardState createState() => _AuthCardState();
}
class _AuthCardState extends State<AuthCard> {
final GlobalKey<FormState> _formKey = GlobalKey();
Map<String, String> _authData = {
'email': '',
'password': '',
};
var _isLoading = false;
final _passwordController = TextEditingController();
Future<void> _submit() async {
if (!_formKey.currentState.validate()) {
// Invalid!
return;
}
_formKey.currentState.save();
setState(() {
_isLoading = true;
});
try {
// Log user in
await Provider.of<Auth>(context, listen: false).login(
_authData['email'],
_authData['password'],
);
String deviceName;
String deviceVersion;
String identifier;
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
try {
if (Platform.isAndroid) {
var build = await deviceInfoPlugin.androidInfo;
deviceName = build.model;
deviceVersion = build.version.toString();
identifier = build.androidId; //UUID for Android
} else if (Platform.isIOS) {
var data = await deviceInfoPlugin.iosInfo;
deviceName = data.name;
deviceVersion = data.systemVersion;
identifier = data.identifierForVendor; //UUID for iOS
}
} on PlatformException {
print('Failed to get platform version');
}
try{
var response = await http.post(
Uri.parse("https://connect-elearning.com/newVersion/APIs/checkIDntfr.php"),
body: {
'IdentifierPst': identifier,
'userNoPst': _authData['email'],
});
Map<String,dynamic> data = jsonDecode(response.body);
String svdIdentifier = data["svdIdentifier"];
String svdUserID = data["svdUserID"];
String realUserID = data["RealUserID"];
if(svdIdentifier != "notFound"){
if(svdIdentifier == identifier && svdUserID == realUserID){
Navigator.pushNamedAndRemoveUntil(context, '/home', (r) => false);
//CommonFunctions.showSuccessToast('Login Successful');
CommonFunctions.showSuccessToast('Login Successful');
} else if(svdIdentifier != identifier || svdUserID != realUserID){
// SharedPreferences preferences = await SharedPreferences.getInstance();
// await preferences.clear();
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Your account is registered for another device, please contact technical support.'),
//title: Text('Your ${svdIdentifier} ${svdUserID} ${realUserID}'),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context, true), // passing true
child: Text('Exit'),
),
],
);
}).then((exit) {
if (exit == null) {SystemNavigator.pop();}
if (exit) {
SystemNavigator.pop();
} else {
SystemNavigator.pop();
}
});
}
} else {
try{
var response = await http.post(
Uri.parse("https://connect-elearning.com/newVersion/APIs/userIDntfrSv.php"),
body: {
'userNoPst': _authData['email'],
'dvNamePst': deviceName,
//'dvOSPst': deviceVersion,
'dvIdntPst': identifier,
});
} catch (e){
print(e);
}
Navigator.pushNamedAndRemoveUntil(context, '/home', (r) => false);
CommonFunctions.showSuccessToast('Login Successful');
}
} catch (e) {
//print("note that ${e}");
}
} on HttpException catch (error) {
var errorMsg = 'Wrong data, you can contact customers services';
CommonFunctions.showErrorDialog(errorMsg, context);
} catch (error) {
//const errorMsg = 'Could not authenticate!, may you need to contact to customers services via whats-app: +201033040777';
//String errorMsg = 'Done!${error}, Go to My courses page';
下一行显示的错误消息
print("errrrrrrrrrrrrrooooor ${error}");
}
setState(() {
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;
return Container(
height: 360,
constraints: BoxConstraints(minHeight: 260),
width: deviceSize.width * 0.8,
padding: EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
//labelText: 'Email Address',
labelText: 'Mobile',
prefixIcon: Icon(
//Icons.mail_outline,
Icons.phone_android,
color: Colors.grey,
), // myIcon is a 48px-wide widget.
),
//keyboardType: TextInputType.emailAddress,
keyboardType: TextInputType.phone,
validator: (input) => input.length < 11
? "Enter valid mobile number!"
: null,
/*validator: (value) {
if (value.isEmpty || !value.contains('@')) {
return 'Invalid email!';
}
},*/
onSaved: (value) {
_authData['email'] = value;
},
),
TextFormField(
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
),
obscureText: true,
controller: _passwordController,
validator: (value) {
if (value.isEmpty || value.length < 4) {
return 'Password is too short!';
}
},
onSaved: (value) {
_authData['password'] = value;
},
),
SizedBox(
height: 20,
),
if (_isLoading)
CircularProgressIndicator()
else
ButtonTheme(
minWidth: deviceSize.width * 0.8,
child: RaisedButton(
child: Text(
'Sign In',
style: TextStyle(fontWeight: FontWeight.bold),
),
onPressed: _submit,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7.0),
side: BorderSide(color: kBlueColor),
),
splashColor: Colors.blueAccent,
padding:
EdgeInsets.symmetric(horizontal: 50.0, vertical: 20),
color: kBlueColor,
textColor: Colors.white,
),
),
SizedBox(
height: 20,
),
/* ButtonTheme(
minWidth: deviceSize.width * 0.8,
child: RaisedButton(
child: Text(
'Create Account',
style: TextStyle(fontWeight: FontWeight.bold),
),
onPressed: () {
Navigator.of(context).pushNamed(SignUpScreen.routeName);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7.0),
side: BorderSide(color: kGreyColor),
),
splashColor: Colors.blueAccent,
padding: EdgeInsets.symmetric(horizontal: 50.0, vertical: 20),
color: kGreyColor,
textColor: kTextColor,
),
),*/
],
),
),
),
);
}
}
编辑:
当我尝试使用命令运行应用程序时
flutter run --release
我在终端中收到这 2 个错误
E/flutter (18074): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:MissingPluginException(在通道 plugins.flutter.io/shared_preferences 上找不到方法 getAll 的实现) E/flutter (18074) :E/flutter (18074): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:MissingPluginException(在通道 flutter.baseflow.com/permi ssions/methods 上找不到方法 checkPermissionStatus 的实现)
我试着跑
flutter clean
flutter pub get
...等等,并没有什么新鲜事
更新
当我将 gradle 更新到最新版本时,应用程序运行良好,除了少数用户仍然遇到相同的错误,我不明白为什么!
解决方案
推荐阅读
- javascript - CSS 错误行为?on :hover 使用 ~
- vue.js - 将 CoreUI 图标添加到 Vue.js 中的 DevExtreme dxDataGrid 列标题
- sql - PSQL 查询根据条件将记录从一个表插入到另一个表
- laravel - 返回带有以选定方式相关的表的查询
- laravel - Auth::attempt not working on laravel passport api
- list - Flutter FireStore 空列表
- javascript - 动态地将系列添加到 highcharts
- python - 使用 numpy 向量化循环
- android - 使用 chrome://inspect/#devices 时看不到代码流动?
- java - 给一个数组给多个方法