mirror of
https://github.com/asjqkkkk/flutter-todos.git
synced 2025-08-06 14:19:24 +08:00
直接干掉定位获取,真麻烦!
This commit is contained in:
@ -6,9 +6,9 @@
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<!--地理位置-->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<!--<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
|
||||
<!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->
|
||||
<!--<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />-->
|
||||
|
||||
|
||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||
|
@ -4,11 +4,8 @@
|
||||
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
#import <flutter_webview_plugin/FlutterWebviewPlugin.h>
|
||||
#import <geolocator/GeolocatorPlugin.h>
|
||||
#import <google_api_availability/GoogleApiAvailabilityPlugin.h>
|
||||
#import <image_crop/ImageCropPlugin.h>
|
||||
#import <image_picker/ImagePickerPlugin.h>
|
||||
#import <location_permissions/LocationPermissionsPlugin.h>
|
||||
#import <package_info/PackageInfoPlugin.h>
|
||||
#import <path_provider/PathProviderPlugin.h>
|
||||
#import <permission_handler/PermissionHandlerPlugin.h>
|
||||
@ -19,11 +16,8 @@
|
||||
|
||||
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
|
||||
[FlutterWebviewPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterWebviewPlugin"]];
|
||||
[GeolocatorPlugin registerWithRegistrar:[registry registrarForPlugin:@"GeolocatorPlugin"]];
|
||||
[GoogleApiAvailabilityPlugin registerWithRegistrar:[registry registrarForPlugin:@"GoogleApiAvailabilityPlugin"]];
|
||||
[ImageCropPlugin registerWithRegistrar:[registry registrarForPlugin:@"ImageCropPlugin"]];
|
||||
[FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]];
|
||||
[LocationPermissionsPlugin registerWithRegistrar:[registry registrarForPlugin:@"LocationPermissionsPlugin"]];
|
||||
[FLTPackageInfoPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPackageInfoPlugin"]];
|
||||
[FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]];
|
||||
[PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]];
|
||||
|
@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
|
@ -101,7 +101,11 @@ class DemoLocalizations {
|
||||
String get cardChangeWithBg => Intl.message('Task icon color follow background', name: 'cardChangeWithBg', desc: '任务图标颜色跟随背景',);
|
||||
String get enableInfiniteScroll => Intl.message('Task card cycle slide', name: 'enableInfiniteScroll', desc: '任务卡片循环滑动',);
|
||||
String get enableWeatherShow => Intl.message('Turn on the weather', name: 'enableWeatherShow', desc: '开启天气',);
|
||||
String get weatherGetWrong => Intl.message('weather acquisition failed', name: 'weatherGetWrong', desc: '天气获取失败',);
|
||||
String get inputCurrentCity => Intl.message('input your city', name: 'inputCurrentCity', desc: '手动输入你的城市',);
|
||||
String get weatherGetWrong => Intl.message('failed to get the weather,please try again', name: 'weatherGetWrong', desc: '天气获取失败,请重新尝试',);
|
||||
String get weatherGetting => Intl.message('the weather is inquiring...', name: 'weatherGetting', desc: '天气获取中...',);
|
||||
String get weatherSuccess => Intl.message('the weather is successful', name: 'weatherSuccess', desc: '天气获取成功',);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -79,6 +79,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"history" : MessageLookupByLibrary.simpleMessage("history"),
|
||||
"hours" : m1,
|
||||
"iconSetting" : MessageLookupByLibrary.simpleMessage("Icon Setting"),
|
||||
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("input your city"),
|
||||
"itemNumber" : m2,
|
||||
"languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"),
|
||||
"loading" : MessageLookupByLibrary.simpleMessage("loading..."),
|
||||
@ -119,7 +120,9 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"unknownDes" : MessageLookupByLibrary.simpleMessage("Unknown permission"),
|
||||
"versionDescription" : MessageLookupByLibrary.simpleMessage("Version Description"),
|
||||
"waitAMoment" : MessageLookupByLibrary.simpleMessage("please wait for a moment..."),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("weather acquisition failed"),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("failed to get the weather,please try again"),
|
||||
"weatherGetting" : MessageLookupByLibrary.simpleMessage("the weather is inquiring..."),
|
||||
"weatherSuccess" : MessageLookupByLibrary.simpleMessage("the weather is successful"),
|
||||
"welcomeWord" : MessageLookupByLibrary.simpleMessage("Hello! "),
|
||||
"work" : MessageLookupByLibrary.simpleMessage("Work"),
|
||||
"writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("Please write at least one task."),
|
||||
|
@ -79,6 +79,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"history" : MessageLookupByLibrary.simpleMessage("历史"),
|
||||
"hours" : m1,
|
||||
"iconSetting" : MessageLookupByLibrary.simpleMessage("图标设置"),
|
||||
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("手动输入你的城市"),
|
||||
"itemNumber" : m2,
|
||||
"languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"),
|
||||
"loading" : MessageLookupByLibrary.simpleMessage("加载中..."),
|
||||
@ -119,7 +120,9 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"unknownDes" : MessageLookupByLibrary.simpleMessage("未知权限"),
|
||||
"versionDescription" : MessageLookupByLibrary.simpleMessage("版本描述"),
|
||||
"waitAMoment" : MessageLookupByLibrary.simpleMessage("请稍后..."),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败"),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败,请重新尝试"),
|
||||
"weatherGetting" : MessageLookupByLibrary.simpleMessage("天气获取中..."),
|
||||
"weatherSuccess" : MessageLookupByLibrary.simpleMessage("天气获取成功"),
|
||||
"welcomeWord" : MessageLookupByLibrary.simpleMessage("你好呀! "),
|
||||
"work" : MessageLookupByLibrary.simpleMessage("工作"),
|
||||
"writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("请至少写下一项任务哦"),
|
||||
|
@ -57,65 +57,62 @@ class FeedbackPageLogic {
|
||||
return;
|
||||
}
|
||||
|
||||
_model.loadingController.setFlag(LoadingFlag.loading);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return GestureDetector(
|
||||
onTap: (){
|
||||
_model.loadingController.setFlag(LoadingFlag.success);
|
||||
return NetLoadingWidget(
|
||||
onRequest: () async{
|
||||
final account =
|
||||
await SharedUtil.instance.getString(Keys.account) ?? "default";
|
||||
_model.loadingController.setFlag(LoadingFlag.loading);
|
||||
ApiService.instance.postSuggestion({
|
||||
"account": account,
|
||||
"suggestion": _model.feedbackContent,
|
||||
"connectWay": _model.contactWay ?? "",
|
||||
}, (CommonBean bean) {
|
||||
_model.loadingController.setFlag(LoadingFlag.success);
|
||||
}, (CommonBean bean) {
|
||||
_model.loadingController.setFlag(LoadingFlag.error);
|
||||
}, (error) {
|
||||
_model.loadingController.setFlag(LoadingFlag.error);
|
||||
}, _model.cancelToken);
|
||||
},
|
||||
child: NetLoadingWidget(
|
||||
loadingController: _model.loadingController,
|
||||
successWidget: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
DemoLocalizations.of(context).submitSuccess,
|
||||
loadingController: _model.loadingController,
|
||||
successWidget: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
DemoLocalizations.of(context).submitSuccess,
|
||||
style: TextStyle(fontSize: 30),
|
||||
),
|
||||
SizedBox(height: 10,),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 10,right: 10),
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).thanksForFeedback,
|
||||
style: TextStyle(fontSize: 30),
|
||||
),
|
||||
SizedBox(height: 10,),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 10,right: 10),
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).thanksForFeedback,
|
||||
style: TextStyle(fontSize: 30),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FlatButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
highlightColor: Theme.of(context).primaryColorLight,
|
||||
colorBrightness: Brightness.dark,
|
||||
splashColor: Theme.of(context).primaryColorDark,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20.0)),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FlatButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
highlightColor: Theme.of(context).primaryColorLight,
|
||||
colorBrightness: Brightness.dark,
|
||||
splashColor: Theme.of(context).primaryColorDark,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20.0)),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
final account =
|
||||
await SharedUtil.instance.getString(Keys.account) ?? "default";
|
||||
// ApiService.instance.postSuggestion({
|
||||
// "account": account,
|
||||
// "suggestion": _model.feedbackContent,
|
||||
// "connectWay": _model.contactWay ?? "",
|
||||
// }, (CommonBean bean) {
|
||||
// _model.loadingController.setFlag(LoadingFlag.success);
|
||||
// }, (CommonBean bean) {
|
||||
// _model.loadingController.setFlag(LoadingFlag.error);
|
||||
// }, (error) {
|
||||
// _model.loadingController.setFlag(LoadingFlag.error);
|
||||
// }, _model.cancelToken);
|
||||
},);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import 'package:todo_list/utils/shared_util.dart';
|
||||
import 'package:todo_list/utils/theme_util.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:todo_list/widgets/net_loading_widget.dart';
|
||||
|
||||
class GlobalLogic{
|
||||
|
||||
final GlobalModel _model;
|
||||
@ -125,18 +127,18 @@ class GlobalLogic{
|
||||
_model.enableWeatherShow = enableWeatherShow;
|
||||
}
|
||||
|
||||
void getWeatherNow(String position,{BuildContext context}){
|
||||
void getWeatherNow(String position,{BuildContext context, LoadingController controller}){
|
||||
ApiService.instance.getWeatherNow((WeatherBean weatherBean){
|
||||
debugPrint("请求结果:${weatherBean.toString()}");
|
||||
_model.weatherBean = weatherBean;
|
||||
_model.enableWeatherShow = true;
|
||||
_model.refresh();
|
||||
if(context != null) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}, (WeatherBean weatherBean){
|
||||
controller?.setFlag(LoadingFlag.success);
|
||||
|
||||
}, (WeatherBean weatherBean){
|
||||
controller?.setFlag(LoadingFlag.error);
|
||||
}, (error){
|
||||
controller?.setFlag(LoadingFlag.error);
|
||||
|
||||
}, {
|
||||
"key": "d381a4276ed349daa3bf63646f12d8ae",
|
||||
|
@ -4,6 +4,7 @@ import 'package:todo_list/json/weather_bean.dart';
|
||||
import 'package:todo_list/logic/all_logic.dart';
|
||||
import 'package:todo_list/model/main_page_model.dart';
|
||||
import 'package:todo_list/utils/theme_util.dart';
|
||||
import 'package:todo_list/widgets/net_loading_widget.dart';
|
||||
|
||||
class GlobalModel extends ChangeNotifier {
|
||||
GlobalLogic logic;
|
||||
@ -38,6 +39,8 @@ class GlobalModel extends ChangeNotifier {
|
||||
String currentPosition = "";
|
||||
//当前天气的json
|
||||
WeatherBean weatherBean;
|
||||
//用于控制天气获取的loading加载框
|
||||
LoadingController loadingController = LoadingController();
|
||||
|
||||
|
||||
//当前语言
|
||||
|
@ -3,17 +3,14 @@ import 'dart:math';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todo_list/config/api_service.dart';
|
||||
import 'package:todo_list/config/provider_config.dart';
|
||||
import 'package:todo_list/i10n/localization_intl.dart';
|
||||
import 'package:todo_list/json/weather_bean.dart';
|
||||
import 'package:todo_list/model/global_model.dart';
|
||||
import 'package:todo_list/pages/language_page.dart';
|
||||
import 'package:todo_list/pages/setting_page.dart';
|
||||
import 'package:todo_list/utils/permission_request_util.dart';
|
||||
import 'package:todo_list/widgets/nav_head.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
import 'image_page.dart';
|
||||
import 'navigator_setting_page.dart';
|
||||
|
@ -2,7 +2,6 @@ import 'dart:math';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todo_list/config/api_service.dart';
|
||||
import 'package:todo_list/config/provider_config.dart';
|
||||
@ -10,6 +9,7 @@ import 'package:todo_list/i10n/localization_intl.dart';
|
||||
import 'package:todo_list/model/global_model.dart';
|
||||
import 'package:todo_list/utils/permission_request_util.dart';
|
||||
import 'package:todo_list/utils/shared_util.dart';
|
||||
import 'package:todo_list/widgets/net_loading_widget.dart';
|
||||
|
||||
import 'all_page.dart';
|
||||
import 'navigator_setting_page.dart';
|
||||
@ -92,69 +92,7 @@ class SettingPage extends StatelessWidget {
|
||||
),
|
||||
value: globalModel.enableWeatherShow,
|
||||
activeColor: Theme.of(context).primaryColor,
|
||||
onChanged: (value) {
|
||||
debugPrint("value:${value}");
|
||||
if (value) {
|
||||
PermissionReqUtil.getInstance().requestPermission(
|
||||
PermissionGroup.locationWhenInUse,
|
||||
context: context, granted: () async {
|
||||
globalModel.enableWeatherShow = true;
|
||||
SharedUtil.instance.saveBoolean(Keys.enableWeatherShow, true);
|
||||
globalModel.refresh();
|
||||
//在android模拟器上无法获取位置
|
||||
Position position = await Geolocator().getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.lowest);
|
||||
final lat = position.latitude;
|
||||
final lon = position.longitude;
|
||||
debugPrint("位置:${position}");
|
||||
SharedUtil.instance
|
||||
.saveString(Keys.currentPosition, "${lat},${lon}");
|
||||
debugPrint("value:${globalModel.enableWeatherShow}");
|
||||
globalModel.logic.getWeatherNow("${lat},${lon}");
|
||||
}, disabled: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text("无法获取定位权限"),
|
||||
content: Form(
|
||||
autovalidate: true,
|
||||
child: TextFormField(
|
||||
validator: (text){
|
||||
globalModel.currentPosition = text;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: "手动输入当前城市",
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).cancel,
|
||||
style: TextStyle(color: Colors.redAccent),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
globalModel.logic.getWeatherNow(globalModel.currentPosition, context: context);
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok,
|
||||
style: TextStyle(color: Colors.greenAccent)),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
globalModel.enableWeatherShow = false;
|
||||
SharedUtil.instance.saveBoolean(Keys.enableWeatherShow, false);
|
||||
globalModel.refresh();
|
||||
}
|
||||
},
|
||||
onChanged: (value) => onWeatherOpen(value, context, globalModel),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(DemoLocalizations.of(context).enableInfiniteScroll),
|
||||
@ -210,4 +148,67 @@ class SettingPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onWeatherOpen(bool value, BuildContext context, GlobalModel globalModel) {
|
||||
if (value) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(DemoLocalizations.of(context).enableWeatherShow),
|
||||
content: Form(
|
||||
autovalidate: true,
|
||||
child: TextFormField(
|
||||
validator: (text){
|
||||
globalModel.currentPosition = text;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: DemoLocalizations.of(context).inputCurrentCity,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).cancel,
|
||||
style: TextStyle(color: Colors.redAccent),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
if(globalModel.currentPosition.isEmpty) return;
|
||||
CancelToken cancelToken = CancelToken();
|
||||
showDialog(context: context, builder: (ctx){
|
||||
return NetLoadingWidget(
|
||||
onRequest: (){
|
||||
globalModel.logic.getWeatherNow(globalModel.currentPosition,controller: globalModel.loadingController);
|
||||
},
|
||||
cancelToken: cancelToken,
|
||||
errorText: DemoLocalizations.of(context).weatherGetWrong,
|
||||
loadingText: DemoLocalizations.of(context).weatherGetting,
|
||||
successText: DemoLocalizations.of(context).weatherSuccess,
|
||||
onSuccess: (){
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
loadingController: globalModel.loadingController,
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok,
|
||||
style: TextStyle(color: Colors.greenAccent)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},);
|
||||
} else {
|
||||
globalModel.enableWeatherShow = false;
|
||||
SharedUtil.instance.saveBoolean(Keys.enableWeatherShow, false);
|
||||
globalModel.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,30 +1,38 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:todo_list/i10n/localization_intl.dart';
|
||||
|
||||
import 'loading_widget.dart';
|
||||
|
||||
class NetLoadingWidget extends StatefulWidget {
|
||||
|
||||
final LoadingController loadingController;
|
||||
final Widget successWidget;
|
||||
final String loadingText;
|
||||
final String errorText;
|
||||
final String successText;
|
||||
final String emptyText;
|
||||
final String idleText;
|
||||
final VoidCallback onRequest;
|
||||
final VoidCallback onSuccess;
|
||||
final CancelToken cancelToken;
|
||||
|
||||
const NetLoadingWidget({Key key, this.loadingController, this.successWidget,}) : super(key: key);
|
||||
const NetLoadingWidget({
|
||||
Key key,
|
||||
this.loadingController,
|
||||
this.successWidget, this.loadingText, this.errorText, this.successText, this.emptyText, this.idleText, this.onRequest, this.cancelToken, this.onSuccess,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_NetLoadingWidgetState createState() => _NetLoadingWidgetState();
|
||||
}
|
||||
|
||||
class _NetLoadingWidgetState extends State<NetLoadingWidget> {
|
||||
|
||||
|
||||
LoadingFlag loadingFlag = LoadingFlag.loading;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
final size = MediaQuery.of(context).size;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black.withOpacity(0.3),
|
||||
body: Container(
|
||||
@ -41,7 +49,31 @@ class _NetLoadingWidgetState extends State<NetLoadingWidget> {
|
||||
child: LoadingWidget(
|
||||
flag: loadingFlag,
|
||||
loadingText: getLoadingText(),
|
||||
successWidget: widget.successWidget,
|
||||
successWidget: widget.successWidget ?? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
widget.successText,
|
||||
style: TextStyle(fontSize: 30),
|
||||
),
|
||||
],
|
||||
),
|
||||
FlatButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
highlightColor: Theme.of(context).primaryColorLight,
|
||||
colorBrightness: Brightness.dark,
|
||||
splashColor: Theme.of(context).primaryColorDark,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20.0)),
|
||||
onPressed: widget.onSuccess ?? (){},
|
||||
child: Text(DemoLocalizations.of(context).ok),
|
||||
)
|
||||
],
|
||||
),
|
||||
errorCallBack: widget.onRequest ?? (){},
|
||||
errorText: getLoadingText(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -49,58 +81,62 @@ class _NetLoadingWidgetState extends State<NetLoadingWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget?.loadingController?._setState(this);
|
||||
if(widget.onRequest != null){
|
||||
widget.onRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget?.cancelToken?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String getLoadingText() {
|
||||
switch (loadingFlag) {
|
||||
case LoadingFlag.loading:
|
||||
return DemoLocalizations.of(context).waitAMoment;
|
||||
return widget.loadingText ?? DemoLocalizations.of(context).waitAMoment;
|
||||
break;
|
||||
case LoadingFlag.error:
|
||||
return DemoLocalizations.of(context).submitAgain;
|
||||
return widget.emptyText ?? DemoLocalizations.of(context).submitAgain;
|
||||
break;
|
||||
case LoadingFlag.success:
|
||||
return DemoLocalizations.of(context).submitSuccess;
|
||||
return widget.successText ?? DemoLocalizations.of(context).submitSuccess;
|
||||
break;
|
||||
case LoadingFlag.empty:
|
||||
return "";
|
||||
return widget.emptyText ?? "";
|
||||
break;
|
||||
case LoadingFlag.idle:
|
||||
return "";
|
||||
return widget.idleText ?? "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//这里面的state没有去执行dispose,不知道会不会内存泄漏
|
||||
class LoadingController{
|
||||
|
||||
|
||||
class LoadingController {
|
||||
_NetLoadingWidgetState _state;
|
||||
|
||||
void setFlag(LoadingFlag loadingFlag){
|
||||
void setFlag(LoadingFlag loadingFlag) {
|
||||
_state?.loadingFlag = loadingFlag;
|
||||
if(_state.mounted){
|
||||
_state?.setState((){});
|
||||
if (_state?.mounted ?? false) {
|
||||
_state?.setState(() {});
|
||||
}
|
||||
print("设置:${_state?.loadingFlag}");
|
||||
}
|
||||
|
||||
|
||||
void _setState(_NetLoadingWidgetState state){
|
||||
if(this?._state == null){
|
||||
void _setState(_NetLoadingWidgetState state) {
|
||||
if (this?._state == null) {
|
||||
this?._state = state;
|
||||
} else {
|
||||
this._state = null;
|
||||
this._state = state;
|
||||
}
|
||||
print("设置了:${this._state}");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -72,8 +72,6 @@ dev_dependencies:
|
||||
pull_to_refresh: ^1.5.0
|
||||
#看图片
|
||||
photo_view: ^0.3.3
|
||||
#地理位置
|
||||
geolocator: ^5.1.1+1
|
||||
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
|
@ -176,9 +176,27 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "weather acquisition failed",
|
||||
"inputCurrentCity": "input your city",
|
||||
"@inputCurrentCity": {
|
||||
"description": "手动输入你的城市",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "failed to get the weather,please try again",
|
||||
"@weatherGetWrong": {
|
||||
"description": "天气获取失败",
|
||||
"description": "天气获取失败,请重新尝试",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetting": "the weather is inquiring...",
|
||||
"@weatherGetting": {
|
||||
"description": "天气获取中...",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherSuccess": "the weather is successful",
|
||||
"@weatherSuccess": {
|
||||
"description": "天气获取成功",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"@@last_modified": "2019-07-24T22:56:02.424158",
|
||||
"@@last_modified": "2019-07-25T11:08:23.468694",
|
||||
"appName": "One Day List",
|
||||
"@appName": {
|
||||
"description": "app的名字",
|
||||
@ -176,9 +176,27 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "weather acquisition failed",
|
||||
"inputCurrentCity": "input your city",
|
||||
"@inputCurrentCity": {
|
||||
"description": "手动输入你的城市",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "failed to get the weather,please try again",
|
||||
"@weatherGetWrong": {
|
||||
"description": "天气获取失败",
|
||||
"description": "天气获取失败,请重新尝试",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetting": "the weather is inquiring...",
|
||||
"@weatherGetting": {
|
||||
"description": "天气获取中...",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherSuccess": "the weather is successful",
|
||||
"@weatherSuccess": {
|
||||
"description": "天气获取成功",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
|
@ -152,9 +152,27 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "天气获取失败",
|
||||
"inputCurrentCity": "手动输入你的城市",
|
||||
"@inputCurrentCity": {
|
||||
"description": "手动输入你的城市",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetWrong": "天气获取失败,请重新尝试",
|
||||
"@weatherGetWrong": {
|
||||
"description": "天气获取失败",
|
||||
"description": "天气获取失败,请重新尝试",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherGetting": "天气获取中...",
|
||||
"@weatherGetting": {
|
||||
"description": "天气获取中...",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"weatherSuccess": "天气获取成功",
|
||||
"@weatherSuccess": {
|
||||
"description": "天气获取成功...",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
|
Reference in New Issue
Block a user