From 96413bd04dfc4e1e41c71446ebd6338d865b7f11 Mon Sep 17 00:00:00 2001 From: luki Date: Sat, 9 Jul 2022 14:46:03 +0200 Subject: [PATCH] fix dlete menu from widget tree --- example/pubspec.lock | 23 ++++++++--------------- lib/src/side_menu_item.dart | 21 +++++++++++++++------ pubspec.lock | 23 ++++++++--------------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index c99e639..1d9f0d0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -49,7 +49,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" cupertino_icons: dependency: "direct main" description: @@ -70,7 +70,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 @@ -108,7 +108,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: @@ -122,7 +122,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -134,7 +134,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: @@ -169,21 +169,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.17.0" diff --git a/lib/src/side_menu_item.dart b/lib/src/side_menu_item.dart index dccb498..b5485c5 100644 --- a/lib/src/side_menu_item.dart +++ b/lib/src/side_menu_item.dart @@ -49,25 +49,34 @@ class _SideMenuItemState extends State { double currentPage = 0; bool isHovered = false; + void _handleChange() { + setState(() { + currentPage = Global.controller.page!; + }); + } + @override void initState() { super.initState(); - _nonNullableWrap(WidgetsBinding.instance)!.addPostFrameCallback((timeStamp) { + _nonNullableWrap(WidgetsBinding.instance)! + .addPostFrameCallback((timeStamp) { // set initialPage setState(() { currentPage = Global.controller.initialPage.toDouble(); }); if (mounted) { // set controller SideMenuItem page controller callback - Global.controller.addListener(() { - setState(() { - currentPage = Global.controller.page!; - }); - }); + Global.controller.addListener(_handleChange); } }); } + @override + void dispose() { + Global.controller.removeListener(_handleChange); + super.dispose(); + } + /// This allows a value of type T or T? /// to be treated as a value of type T?. /// diff --git a/pubspec.lock b/pubspec.lock index 185e750..f4bed96 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,14 +49,14 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -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: @@ -108,7 +108,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -120,7 +120,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: @@ -155,21 +155,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.17.0"