我正在 Android Studio 上运行 Flutter 应用程序,该应用程序连接到 Cpanel 中的面板控制服务器。当我运行该应用程序时,它卡在徽标中并且无法进入主屏幕。
在控制台中,我收到以下错误消息:
[错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:FormatException:无法将空字符串解析为版本 E/flutter (1298): #0 Version.parse (包:version/version.dart:162:7)
我已尝试以下方法来修复错误:
1-我已检查 pubspec.yaml 文件中的版本字符串,它是有效的。 2-我已重新启动 Android Studio 和我的 Android 设备。 3-我已经清除了 Flutter 应用程序的缓存和数据。 4-我已卸载并重新安装 Flutter 应用程序。 但是,我仍然收到错误。
我不确定是什么导致了错误或如何修复它。谁能帮我? 这是我从控制台得到的信息
Performing hot restart...
Syncing files to device SM A536E...
Restarted application in 4.437ms.
W/FLTFireMsgService(17654): Attempted to start a duplicate background isolate. Returning...
I/FLTFireMsgService(17654): FlutterFirebaseMessagingBackgroundService started!
I/flutter (17654): API is https://dchopinamerica.com/partner/api/v1/get_settings
I/flutter (17654): pra are {}
I/flutter (17654):
I/flutter (17654): API is https://dchopinamerica.com/partner/api/v1/get_settings
I/flutter (17654): pra are {}
I/flutter (17654): response is {"error":false,"message":"setting recieved Successfully","data":{"general_settings":{"company_title":"eDemand - On Demand Services","support_name":"eDemand","support_email":"[email protected]","phone":"9876543210","system_timezone_gmt":"+05:30","system_timezone":"Asia/Kolkata","max_serviceable_distance":"50","country_code":"+7 840","primary_color":"#081269","secondary_color":"#fcfcfc","primary_shadow":"#ffffff","otp_system":"0","booking_auto_cancle_duration":"1130","address":"<p>#123, Time Square, Bhuj - India</p>","short_description":"<p>eDemand- On Demand services</p>","copyright_details":"<p><strong>Copyright © </strong>2022 eDemand. All rights reserved.</p>","support_hours":"<p>09:00 AM to 06:00PM IST</p>","login_image":"Login_BG.jpg","favicon":"1696170673_db0cc9779c9498b8695c.png","logo":"1696170673_d687beb509c96f7c6c42.png","half_logo":"1696170673_9bf9f2f74c387f1785c8.png","partner_favicon":"1696170673_eeeb76131
E/flutter (17654): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Cannot parse empty string into version
E/flutter (17654): #0 Version.parse (package:version/version.dart:162:7)
E/flutter (17654): #1 _SplashScreenState.build.<anonymous closure> (package:e_demand/ui/screens/splash_screen.dart:133:48)
E/flutter (17654): <asynchronous suspension>
E/flutter (17654):
这是启动画面
import 'package:e_demand/app/generalImports.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({final Key? key}) : super(key: key);
@override
State<SplashScreen> createState() => _SplashScreenState();
static Route route(final RouteSettings routeSettings) => CupertinoPageRoute(
builder: (final _) => const SplashScreen(),
);
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
Future.delayed(Duration.zero).then((final value) {
context.read<CountryCodeCubit>().loadAllCountryCode(context);
context.read<SystemSettingCubit>().getSystemSettings();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: AppColors.splashScreenGradientTopColor,
systemNavigationBarColor: AppColors.splashScreenGradientBottomColor,
statusBarIconBrightness: Brightness.light,
systemNavigationBarIconBrightness: Brightness.light),
);
});
Hive.box(userDetailBoxKey).toMap();
//
context.read<UserDetailsCubit>().loadUserDetails();
//
//if already we have lat-long of customer then no need to get it again
if (Hive.box(userDetailBoxKey).get(longitudeKey) == null &&
Hive.box(userDetailBoxKey).get(latitudeKey) == null) {
GetLocation().requestPermission(onGranted: (position) {
//if permission is allowed recently then this method will invoke,
// we will store latitude and longitude
Hive.box(userDetailBoxKey).put(longitudeKey, position.longitude);
Hive.box(userDetailBoxKey).put(latitudeKey, position.latitude);
}, allowed: (position) {
//if permission is allowed already then this method will invoke,
// we will store latitude and longitude
Hive.box(userDetailBoxKey).put(longitudeKey, position.longitude);
Hive.box(userDetailBoxKey).put(latitudeKey, position.latitude);
}, onRejected: () {
//if permission is rejected then we will store empty string
Hive.box(userDetailBoxKey).put(longitudeKey, "");
Hive.box(userDetailBoxKey).put(latitudeKey, "");
});
context.read<GeolocationCubit>().getGeoLocation();
}
}
Future<void> _checkAuthentication({required final bool isNeedToShowAppUpdate}) async {
await Future.delayed(const Duration(seconds: 3), () {
final authStatus = context.read<AuthenticationCubit>().state;
if (authStatus is AuthenticatedState) {
Navigator.pushReplacementNamed(context, navigationRoute);
//
if (isNeedToShowAppUpdate) {
//if need to show app update screen then
// we will push update screen, with not now button option
Navigator.pushNamed(context, appUpdateScreen, arguments: {"isForceUpdate": false});
}
return;
}
if (authStatus is UnAuthenticatedState) {
//
final isFirst = Hive.box(authStatusBoxKey).get(isUserFirstTime);
final isSkippedLoginBefore =
Hive.box(authStatusBoxKey).get(isUserSkippedLoginBefore) ?? false;
//
if (isFirst == null) {
Hive.box(authStatusBoxKey).put(isUserFirstTime, false);
Navigator.pushReplacementNamed(context, onBoardingRoute);
} else if (isSkippedLoginBefore) {
Navigator.pushReplacementNamed(context, navigationRoute);
} else {
Navigator.pushReplacementNamed(
context,
loginRoute,
arguments: {"source": "splashScreen"},
);
}
if (isNeedToShowAppUpdate) {
//if need to show app update screen then
// we will push update screen, with not now button option
Navigator.pushNamed(context, appUpdateScreen, arguments: {"isForceUpdate": false});
}
}
});
}
@override
Widget build(final BuildContext context) => Scaffold(
body: BlocConsumer<SystemSettingCubit, SystemSettingState>(
listener: (final BuildContext context, final SystemSettingState state) async {
if (state is SystemSettingFetchSuccess) {
final generalSettings = state.systemSettingDetails.generalSettings!;
//
// if maintenance mode is enable then we will redirect maintenance mode screen
if (generalSettings.customerAppMaintenanceMode == '1') {
await Navigator.pushReplacementNamed(
context,
maintenanceModeScreen,
arguments: generalSettings.messageForCustomerApplication,
);
return;
}
// here we will check current version and updated version from panel
// if application current version is less than updated version then
// we will show app update screen
final String? latestAndroidVersion = generalSettings.customerCurrentVersionAndroidApp;
final latestIOSVersion = generalSettings.customerCurrentVersionIosApp;
final packageInfo = await PackageInfo.fromPlatform();
final currentApplicationVersion = packageInfo.version;
final currentVersion = Version.parse(currentApplicationVersion);
final latestVersionAndroid = Version.parse(latestAndroidVersion ?? '1.0.0');
final latestVersionIos = Version.parse(latestIOSVersion ?? '1.0.0');
if ((Platform.isAndroid && latestVersionAndroid > currentVersion) ||
(Platform.isIOS && latestVersionIos > currentVersion)) {
// If it is force update then we will show app update with only Update button
if (generalSettings.customerCompulsaryUpdateForceUpdate == '1') {
await Navigator.pushReplacementNamed(
context,
appUpdateScreen,
arguments: {'isForceUpdate': true},
);
return;
} else {
// If it is normal update then
// we will pass true here for isNeedToShowAppUpdate
_checkAuthentication(isNeedToShowAppUpdate: true);
}
} else {
//if no update available then we will pass false here for isNeedToShowAppUpdate
_checkAuthentication(isNeedToShowAppUpdate: false);
}
}
},
builder: (final BuildContext context, final SystemSettingState state) {
if (state is SystemSettingFetchFailure) {
return ErrorContainer(
errorMessage: state.errorMessage.toString().translate(context: context),
onTapRetry: () {
context.read<SystemSettingCubit>().getSystemSettings();
},
);
}
return Stack(
children: [
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xff2050D2),
Color(0xff143386),
],
stops: [0, 1],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
child: Center(
child:
UiUtils.getSvgImage(svgImage: "splash_logo.svg", height: 240, width: 220),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 50),
child: Align(
alignment: Alignment.bottomCenter,
child: UiUtils.getSvgImage(svgImage: "wrteam_logo.svg", width: 135, height: 25),
),
),
],
);
},
),
);
}
看起来这段代码导致了这个问题。
final currentApplicationVersion = packageInfo.version;
final currentVersion = Version.parse(currentApplicationVersion); // unable to parse the empty string into Version class
尝试记录
currentApplicationVersion
并检查它是否为空。
解析前请确保不为空。