Skip to content

Commit

Permalink
fix : fix major bugs
Browse files Browse the repository at this point in the history
* fix infinit loading widget when close app with back button and widget is main widget
  • Loading branch information
liodali committed Jun 6, 2022
1 parent 6346bda commit c03978b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.34.0"
version: "0.34.0+1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand Down
16 changes: 8 additions & 8 deletions flutter_osm_interface/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
dio:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -94,7 +94,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -108,7 +108,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
permission_handler:
dependency: "direct main"
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -183,7 +183,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
typed_data:
dependency: transitive
description:
Expand All @@ -197,7 +197,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.15.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.5.0"
3 changes: 3 additions & 0 deletions lib/src/controller/osm/osm_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class MobileOSMController extends IBaseOSMController {

osmPlatform.onMapRestored(_idMap).listen((event) {
Future.delayed(Duration(milliseconds: 300), () {
if(!_osmFlutterState.widget.mapIsReadyListener.value){
_osmFlutterState.widget.mapIsReadyListener.value = true;
}
_osmFlutterState.widget.controller.osMMixin?.mapRestored();
});
});
Expand Down
36 changes: 22 additions & 14 deletions lib/src/widgets/mobile_osm_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ class MobileOsmFlutterState extends State<MobileOsmFlutter>
late ValueNotifier<Orientation> orientation;
late ValueNotifier<Size> sizeNotifier;
ValueNotifier<bool> setCache = ValueNotifier(false);
ValueNotifier<bool> isFirstLaunched = ValueNotifier(false);
late ValueNotifier<bool> isFirstLaunched;

@override
void initState() {
super.initState();
keyUUID = Uuid().v4();
isFirstLaunched = ValueNotifier(false);
WidgetsBinding.instance.addObserver(this);
Future.delayed(Duration.zero, () async {
orientation = ValueNotifier(Orientation.values[MediaQuery.of(context).orientation.index]);
Expand Down Expand Up @@ -138,6 +139,7 @@ class MobileOsmFlutterState extends State<MobileOsmFlutter>
orientation.value = Orientation.values[nIndex];
} else {
if (sizeNotifier.value != MediaQuery.of(context).size) {
setCache.value = true;
sizeNotifier.value = MediaQuery.of(context).size;
}
}
Expand All @@ -149,14 +151,21 @@ class MobileOsmFlutterState extends State<MobileOsmFlutter>
@override
bool get mounted => super.mounted;

@override
void didUpdateWidget(covariant MobileOsmFlutter oldWidget) {
void saveCache() {
if (Platform.isAndroid && isFirstLaunched.value) {
if (!setCache.value) {
if (setCache.value == false) {
setCache.value = true;
Future.microtask(() async => await _osmController?.saveCacheMap());
}
}
}

@override
void didUpdateWidget(covariant MobileOsmFlutter oldWidget) {
// saveCache();
if (widget.mapIsReadyListener.value) {
saveCache();
}
super.didUpdateWidget(oldWidget);
if (this.widget != oldWidget &&
Platform.isAndroid &&
Expand Down Expand Up @@ -243,22 +252,21 @@ class PlatformView extends StatelessWidget {

@override
Widget build(BuildContext context) {
Widget widgetMap = AndroidView(
key: androidKey,
viewType: 'plugins.dali.hamza/osmview',
onPlatformViewCreated: onPlatformCreatedView,
creationParams: uuidMapCache,
//creationParamsCodec: null,
creationParamsCodec: StandardMethodCodec().messageCodec,
);
if (defaultTargetPlatform == TargetPlatform.iOS) {
widgetMap = UiKitView(
return UiKitView(
// key: mobileKey,
viewType: 'plugins.dali.hamza/osmview',
onPlatformViewCreated: onPlatformCreatedView,
//creationParamsCodec: StandardMessageCodec(),
);
}
return widgetMap;
return AndroidView(
key: androidKey,
viewType: 'plugins.dali.hamza/osmview',
onPlatformViewCreated: onPlatformCreatedView,
creationParams: uuidMapCache,
//creationParamsCodec: null,
creationParamsCodec: StandardMethodCodec().messageCodec,
);
}
}

0 comments on commit c03978b

Please sign in to comment.