直接干掉定位获取,真麻烦!

This commit is contained in:
oldchen
2019-07-25 11:08:56 +08:00
parent 32af05900c
commit 03e9aa07d1
16 changed files with 263 additions and 173 deletions

View File

@ -6,9 +6,9 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <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_COARSE_LOCATION" />-->
<uses-permission android:name="android.permission.ACCESS_FINE_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_LOCATION_EXTRA_COMMANDS" />-->
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <!-- io.flutter.app.FlutterApplication is an android.app.Application that

View File

@ -4,11 +4,8 @@
#import "GeneratedPluginRegistrant.h" #import "GeneratedPluginRegistrant.h"
#import <flutter_webview_plugin/FlutterWebviewPlugin.h> #import <flutter_webview_plugin/FlutterWebviewPlugin.h>
#import <geolocator/GeolocatorPlugin.h>
#import <google_api_availability/GoogleApiAvailabilityPlugin.h>
#import <image_crop/ImageCropPlugin.h> #import <image_crop/ImageCropPlugin.h>
#import <image_picker/ImagePickerPlugin.h> #import <image_picker/ImagePickerPlugin.h>
#import <location_permissions/LocationPermissionsPlugin.h>
#import <package_info/PackageInfoPlugin.h> #import <package_info/PackageInfoPlugin.h>
#import <path_provider/PathProviderPlugin.h> #import <path_provider/PathProviderPlugin.h>
#import <permission_handler/PermissionHandlerPlugin.h> #import <permission_handler/PermissionHandlerPlugin.h>
@ -19,11 +16,8 @@
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry { + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[FlutterWebviewPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterWebviewPlugin"]]; [FlutterWebviewPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterWebviewPlugin"]];
[GeolocatorPlugin registerWithRegistrar:[registry registrarForPlugin:@"GeolocatorPlugin"]];
[GoogleApiAvailabilityPlugin registerWithRegistrar:[registry registrarForPlugin:@"GoogleApiAvailabilityPlugin"]];
[ImageCropPlugin registerWithRegistrar:[registry registrarForPlugin:@"ImageCropPlugin"]]; [ImageCropPlugin registerWithRegistrar:[registry registrarForPlugin:@"ImageCropPlugin"]];
[FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]]; [FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]];
[LocationPermissionsPlugin registerWithRegistrar:[registry registrarForPlugin:@"LocationPermissionsPlugin"]];
[FLTPackageInfoPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPackageInfoPlugin"]]; [FLTPackageInfoPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPackageInfoPlugin"]];
[FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]]; [FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]];
[PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]]; [PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]];

View File

@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>

View File

@ -101,7 +101,11 @@ class DemoLocalizations {
String get cardChangeWithBg => Intl.message('Task icon color follow background', name: 'cardChangeWithBg', desc: '任务图标颜色跟随背景',); 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 enableInfiniteScroll => Intl.message('Task card cycle slide', name: 'enableInfiniteScroll', desc: '任务卡片循环滑动',);
String get enableWeatherShow => Intl.message('Turn on the weather', name: 'enableWeatherShow', 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 weatherplease 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: '天气获取成功',);

View File

@ -79,6 +79,7 @@ class MessageLookup extends MessageLookupByLibrary {
"history" : MessageLookupByLibrary.simpleMessage("history"), "history" : MessageLookupByLibrary.simpleMessage("history"),
"hours" : m1, "hours" : m1,
"iconSetting" : MessageLookupByLibrary.simpleMessage("Icon Setting"), "iconSetting" : MessageLookupByLibrary.simpleMessage("Icon Setting"),
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("input your city"),
"itemNumber" : m2, "itemNumber" : m2,
"languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"), "languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"),
"loading" : MessageLookupByLibrary.simpleMessage("loading..."), "loading" : MessageLookupByLibrary.simpleMessage("loading..."),
@ -119,7 +120,9 @@ class MessageLookup extends MessageLookupByLibrary {
"unknownDes" : MessageLookupByLibrary.simpleMessage("Unknown permission"), "unknownDes" : MessageLookupByLibrary.simpleMessage("Unknown permission"),
"versionDescription" : MessageLookupByLibrary.simpleMessage("Version Description"), "versionDescription" : MessageLookupByLibrary.simpleMessage("Version Description"),
"waitAMoment" : MessageLookupByLibrary.simpleMessage("please wait for a moment..."), "waitAMoment" : MessageLookupByLibrary.simpleMessage("please wait for a moment..."),
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("weather acquisition failed"), "weatherGetWrong" : MessageLookupByLibrary.simpleMessage("failed to get the weatherplease try again"),
"weatherGetting" : MessageLookupByLibrary.simpleMessage("the weather is inquiring..."),
"weatherSuccess" : MessageLookupByLibrary.simpleMessage("the weather is successful"),
"welcomeWord" : MessageLookupByLibrary.simpleMessage("Hello! "), "welcomeWord" : MessageLookupByLibrary.simpleMessage("Hello! "),
"work" : MessageLookupByLibrary.simpleMessage("Work"), "work" : MessageLookupByLibrary.simpleMessage("Work"),
"writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("Please write at least one task."), "writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("Please write at least one task."),

View File

@ -79,6 +79,7 @@ class MessageLookup extends MessageLookupByLibrary {
"history" : MessageLookupByLibrary.simpleMessage("历史"), "history" : MessageLookupByLibrary.simpleMessage("历史"),
"hours" : m1, "hours" : m1,
"iconSetting" : MessageLookupByLibrary.simpleMessage("图标设置"), "iconSetting" : MessageLookupByLibrary.simpleMessage("图标设置"),
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("手动输入你的城市"),
"itemNumber" : m2, "itemNumber" : m2,
"languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"), "languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"),
"loading" : MessageLookupByLibrary.simpleMessage("加载中..."), "loading" : MessageLookupByLibrary.simpleMessage("加载中..."),
@ -119,7 +120,9 @@ class MessageLookup extends MessageLookupByLibrary {
"unknownDes" : MessageLookupByLibrary.simpleMessage("未知权限"), "unknownDes" : MessageLookupByLibrary.simpleMessage("未知权限"),
"versionDescription" : MessageLookupByLibrary.simpleMessage("版本描述"), "versionDescription" : MessageLookupByLibrary.simpleMessage("版本描述"),
"waitAMoment" : MessageLookupByLibrary.simpleMessage("请稍后..."), "waitAMoment" : MessageLookupByLibrary.simpleMessage("请稍后..."),
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败"), "weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败,请重新尝试"),
"weatherGetting" : MessageLookupByLibrary.simpleMessage("天气获取中..."),
"weatherSuccess" : MessageLookupByLibrary.simpleMessage("天气获取成功"),
"welcomeWord" : MessageLookupByLibrary.simpleMessage("你好呀! "), "welcomeWord" : MessageLookupByLibrary.simpleMessage("你好呀! "),
"work" : MessageLookupByLibrary.simpleMessage("工作"), "work" : MessageLookupByLibrary.simpleMessage("工作"),
"writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("请至少写下一项任务哦"), "writeAtLeastOneTaskItem" : MessageLookupByLibrary.simpleMessage("请至少写下一项任务哦"),

View File

@ -57,65 +57,62 @@ class FeedbackPageLogic {
return; return;
} }
_model.loadingController.setFlag(LoadingFlag.loading);
showDialog( showDialog(
context: context, context: context,
builder: (ctx) { builder: (ctx) {
return GestureDetector( return NetLoadingWidget(
onTap: (){ onRequest: () async{
_model.loadingController.setFlag(LoadingFlag.success); 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,
loadingController: _model.loadingController, successWidget: Column(
successWidget: Column( mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
children: <Widget>[ Column(
Column( children: <Widget>[
children: <Widget>[ Text(
Text( DemoLocalizations.of(context).submitSuccess,
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), style: TextStyle(fontSize: 30),
), ),
SizedBox(height: 10,), ),
Container( ],
margin: EdgeInsets.only(left: 10,right: 10), ),
child: Text( FlatButton(
DemoLocalizations.of(context).thanksForFeedback, color: Theme.of(context).primaryColor,
style: TextStyle(fontSize: 30), highlightColor: Theme.of(context).primaryColorLight,
), colorBrightness: Brightness.dark,
), splashColor: Theme.of(context).primaryColorDark,
], shape: RoundedRectangleBorder(
), borderRadius: BorderRadius.circular(20.0)),
FlatButton( onPressed: () {
color: Theme.of(context).primaryColor, Navigator.of(context).pop();
highlightColor: Theme.of(context).primaryColorLight, Navigator.of(context).pop();
colorBrightness: Brightness.dark, },
splashColor: Theme.of(context).primaryColorDark, child: Text(DemoLocalizations.of(context).ok),
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);
} }
} }

View File

@ -8,6 +8,8 @@ import 'package:todo_list/utils/shared_util.dart';
import 'package:todo_list/utils/theme_util.dart'; import 'package:todo_list/utils/theme_util.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:todo_list/widgets/net_loading_widget.dart';
class GlobalLogic{ class GlobalLogic{
final GlobalModel _model; final GlobalModel _model;
@ -125,18 +127,18 @@ class GlobalLogic{
_model.enableWeatherShow = enableWeatherShow; _model.enableWeatherShow = enableWeatherShow;
} }
void getWeatherNow(String position,{BuildContext context}){ void getWeatherNow(String position,{BuildContext context, LoadingController controller}){
ApiService.instance.getWeatherNow((WeatherBean weatherBean){ ApiService.instance.getWeatherNow((WeatherBean weatherBean){
debugPrint("请求结果:${weatherBean.toString()}"); debugPrint("请求结果:${weatherBean.toString()}");
_model.weatherBean = weatherBean; _model.weatherBean = weatherBean;
_model.enableWeatherShow = true; _model.enableWeatherShow = true;
_model.refresh(); _model.refresh();
if(context != null) { controller?.setFlag(LoadingFlag.success);
Navigator.pop(context);
}
}, (WeatherBean weatherBean){
}, (WeatherBean weatherBean){
controller?.setFlag(LoadingFlag.error);
}, (error){ }, (error){
controller?.setFlag(LoadingFlag.error);
}, { }, {
"key": "d381a4276ed349daa3bf63646f12d8ae", "key": "d381a4276ed349daa3bf63646f12d8ae",

View File

@ -4,6 +4,7 @@ import 'package:todo_list/json/weather_bean.dart';
import 'package:todo_list/logic/all_logic.dart'; import 'package:todo_list/logic/all_logic.dart';
import 'package:todo_list/model/main_page_model.dart'; import 'package:todo_list/model/main_page_model.dart';
import 'package:todo_list/utils/theme_util.dart'; import 'package:todo_list/utils/theme_util.dart';
import 'package:todo_list/widgets/net_loading_widget.dart';
class GlobalModel extends ChangeNotifier { class GlobalModel extends ChangeNotifier {
GlobalLogic logic; GlobalLogic logic;
@ -38,6 +39,8 @@ class GlobalModel extends ChangeNotifier {
String currentPosition = ""; String currentPosition = "";
//当前天气的json //当前天气的json
WeatherBean weatherBean; WeatherBean weatherBean;
//用于控制天气获取的loading加载框
LoadingController loadingController = LoadingController();
//当前语言 //当前语言

View File

@ -3,17 +3,14 @@ import 'dart:math';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.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/config/provider_config.dart';
import 'package:todo_list/i10n/localization_intl.dart'; import 'package:todo_list/i10n/localization_intl.dart';
import 'package:todo_list/json/weather_bean.dart'; import 'package:todo_list/json/weather_bean.dart';
import 'package:todo_list/model/global_model.dart'; import 'package:todo_list/model/global_model.dart';
import 'package:todo_list/pages/language_page.dart'; import 'package:todo_list/pages/language_page.dart';
import 'package:todo_list/pages/setting_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:todo_list/widgets/nav_head.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:geolocator/geolocator.dart';
import 'image_page.dart'; import 'image_page.dart';
import 'navigator_setting_page.dart'; import 'navigator_setting_page.dart';

View File

@ -2,7 +2,6 @@ import 'dart:math';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:todo_list/config/api_service.dart'; import 'package:todo_list/config/api_service.dart';
import 'package:todo_list/config/provider_config.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/model/global_model.dart';
import 'package:todo_list/utils/permission_request_util.dart'; import 'package:todo_list/utils/permission_request_util.dart';
import 'package:todo_list/utils/shared_util.dart'; import 'package:todo_list/utils/shared_util.dart';
import 'package:todo_list/widgets/net_loading_widget.dart';
import 'all_page.dart'; import 'all_page.dart';
import 'navigator_setting_page.dart'; import 'navigator_setting_page.dart';
@ -92,69 +92,7 @@ class SettingPage extends StatelessWidget {
), ),
value: globalModel.enableWeatherShow, value: globalModel.enableWeatherShow,
activeColor: Theme.of(context).primaryColor, activeColor: Theme.of(context).primaryColor,
onChanged: (value) { onChanged: (value) => onWeatherOpen(value, context, globalModel),
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();
}
},
), ),
SwitchListTile( SwitchListTile(
title: Text(DemoLocalizations.of(context).enableInfiniteScroll), 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();
}
}
} }

View File

@ -1,30 +1,38 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:todo_list/i10n/localization_intl.dart'; import 'package:todo_list/i10n/localization_intl.dart';
import 'loading_widget.dart'; import 'loading_widget.dart';
class NetLoadingWidget extends StatefulWidget { class NetLoadingWidget extends StatefulWidget {
final LoadingController loadingController; final LoadingController loadingController;
final Widget successWidget; 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 @override
_NetLoadingWidgetState createState() => _NetLoadingWidgetState(); _NetLoadingWidgetState createState() => _NetLoadingWidgetState();
} }
class _NetLoadingWidgetState extends State<NetLoadingWidget> { class _NetLoadingWidgetState extends State<NetLoadingWidget> {
LoadingFlag loadingFlag = LoadingFlag.loading; LoadingFlag loadingFlag = LoadingFlag.loading;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final size = MediaQuery.of(context).size; final size = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
backgroundColor: Colors.black.withOpacity(0.3), backgroundColor: Colors.black.withOpacity(0.3),
body: Container( body: Container(
@ -41,7 +49,31 @@ class _NetLoadingWidgetState extends State<NetLoadingWidget> {
child: LoadingWidget( child: LoadingWidget(
flag: loadingFlag, flag: loadingFlag,
loadingText: getLoadingText(), 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 @override
void initState() { void initState() {
super.initState(); super.initState();
widget?.loadingController?._setState(this); widget?.loadingController?._setState(this);
if(widget.onRequest != null){
widget.onRequest();
}
}
@override
void dispose() {
widget?.cancelToken?.cancel();
super.dispose();
} }
String getLoadingText() { String getLoadingText() {
switch (loadingFlag) { switch (loadingFlag) {
case LoadingFlag.loading: case LoadingFlag.loading:
return DemoLocalizations.of(context).waitAMoment; return widget.loadingText ?? DemoLocalizations.of(context).waitAMoment;
break; break;
case LoadingFlag.error: case LoadingFlag.error:
return DemoLocalizations.of(context).submitAgain; return widget.emptyText ?? DemoLocalizations.of(context).submitAgain;
break; break;
case LoadingFlag.success: case LoadingFlag.success:
return DemoLocalizations.of(context).submitSuccess; return widget.successText ?? DemoLocalizations.of(context).submitSuccess;
break; break;
case LoadingFlag.empty: case LoadingFlag.empty:
return ""; return widget.emptyText ?? "";
break; break;
case LoadingFlag.idle: case LoadingFlag.idle:
return ""; return widget.idleText ?? "";
break; break;
} }
} }
} }
//这里面的state没有去执行dispose不知道会不会内存泄漏 //这里面的state没有去执行dispose不知道会不会内存泄漏
class LoadingController{ class LoadingController {
_NetLoadingWidgetState _state; _NetLoadingWidgetState _state;
void setFlag(LoadingFlag loadingFlag){ void setFlag(LoadingFlag loadingFlag) {
_state?.loadingFlag = loadingFlag; _state?.loadingFlag = loadingFlag;
if(_state.mounted){ if (_state?.mounted ?? false) {
_state?.setState((){}); _state?.setState(() {});
} }
print("设置:${_state?.loadingFlag}"); print("设置:${_state?.loadingFlag}");
} }
void _setState(_NetLoadingWidgetState state) {
void _setState(_NetLoadingWidgetState state){ if (this?._state == null) {
if(this?._state == null){
this?._state = state; this?._state = state;
} else { } else {
this._state = null; this._state = null;
this._state = state; this._state = state;
} }
print("设置了:${this._state}");
} }
} }

View File

@ -72,8 +72,6 @@ dev_dependencies:
pull_to_refresh: ^1.5.0 pull_to_refresh: ^1.5.0
#看图片 #看图片
photo_view: ^0.3.3 photo_view: ^0.3.3
#地理位置
geolocator: ^5.1.1+1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the

View File

@ -176,9 +176,27 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"weatherGetWrong": "weather acquisition failed", "inputCurrentCity": "input your city",
"@inputCurrentCity": {
"description": "手动输入你的城市",
"type": "text",
"placeholders": {}
},
"weatherGetWrong": "failed to get the weatherplease try again",
"@weatherGetWrong": { "@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", "type": "text",
"placeholders": {} "placeholders": {}
}, },

View File

@ -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": "One Day List",
"@appName": { "@appName": {
"description": "app的名字", "description": "app的名字",
@ -176,9 +176,27 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"weatherGetWrong": "weather acquisition failed", "inputCurrentCity": "input your city",
"@inputCurrentCity": {
"description": "手动输入你的城市",
"type": "text",
"placeholders": {}
},
"weatherGetWrong": "failed to get the weatherplease try again",
"@weatherGetWrong": { "@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", "type": "text",
"placeholders": {} "placeholders": {}
}, },

View File

@ -152,9 +152,27 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"weatherGetWrong": "天气获取失败", "inputCurrentCity": "手动输入你的城市",
"@inputCurrentCity": {
"description": "手动输入你的城市",
"type": "text",
"placeholders": {}
},
"weatherGetWrong": "天气获取失败,请重新尝试",
"@weatherGetWrong": { "@weatherGetWrong": {
"description": "天气获取失败", "description": "天气获取失败,请重新尝试",
"type": "text",
"placeholders": {}
},
"weatherGetting": "天气获取中...",
"@weatherGetting": {
"description": "天气获取中...",
"type": "text",
"placeholders": {}
},
"weatherSuccess": "天气获取成功",
"@weatherSuccess": {
"description": "天气获取成功...",
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },