Skip to content

Commit

Permalink
Merge pull request #15 from gudaja/fix_dispose
Browse files Browse the repository at this point in the history
fix dlete menu from widget tree
  • Loading branch information
Jamalianpour authored Jul 21, 2022
2 parents 2d8efb2 + 96413bd commit 2c49e1d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
23 changes: 8 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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"
21 changes: 15 additions & 6 deletions lib/src/side_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,34 @@ class _SideMenuItemState extends State<SideMenuItem> {
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?.
///
Expand Down
23 changes: 8 additions & 15 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -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:
Expand Down Expand Up @@ -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"

0 comments on commit 2c49e1d

Please sign in to comment.