From 3d0fecd14b257593dd6b4e5e53a089abf57becad Mon Sep 17 00:00:00 2001 From: jonas-martinez Date: Fri, 6 May 2022 12:02:50 +0200 Subject: [PATCH 1/2] fix: Fix overlayEntry crash --- .../flutter_playground/lib/left_menu.dart | 1 - .../lib/pages/overlay_entry_example.dart | 121 ++++++++++-------- lib/layout/lenra_overlay_entry.dart | 2 +- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/examples/flutter_playground/lib/left_menu.dart b/examples/flutter_playground/lib/left_menu.dart index f9586e1..20f17ff 100644 --- a/examples/flutter_playground/lib/left_menu.dart +++ b/examples/flutter_playground/lib/left_menu.dart @@ -48,7 +48,6 @@ class LeftMenu extends StatelessWidget { createMenu(context, 'Textfield Examples', textFieldExample), createMenu(context, 'Wrap Examples', wrapExample), createMenu(context, 'stackExample', stackExample), - createMenu(context, 'overlayEntry Example', overlayEntryExample), createMenu(context, 'OverlayEntry Examples', overlayEntryExample), createMenu(context, 'Slider Examples', sliderExample), createMenu(context, 'Text Example', textExample), diff --git a/examples/flutter_playground/lib/pages/overlay_entry_example.dart b/examples/flutter_playground/lib/pages/overlay_entry_example.dart index 89efcc0..cb198a0 100644 --- a/examples/flutter_playground/lib/pages/overlay_entry_example.dart +++ b/examples/flutter_playground/lib/pages/overlay_entry_example.dart @@ -15,45 +15,94 @@ class OverlayEntryExample extends StatefulWidget { class _OverlayEntryExampleState extends State { Widget test = const SizedBox.shrink(); bool showOverlay = false; - bool showOverlay3 = true; + bool showOverlay2 = true; + bool removeOverlays = false; @override Widget build(BuildContext context) { return Center( child: LenraFlex( direction: Axis.vertical, + crossAxisAlignment: CrossAxisAlignment.center, spacing: 2, children: [ LenraText(text: "You can show another overlay by clicking on the button below."), - LenraButton( - text: "Show", - onPressed: () { - setState(() { - showOverlay = true; - }); - }, + LenraFlex( + spacing: 2, + children: [ + LenraButton( + text: "Show", + onPressed: () { + setState(() { + showOverlay = true; + removeOverlays = false; + }); + }, + ), + LenraButton( + text: "Remove overlays", + onPressed: () { + setState(() { + removeOverlays = true; + }); + }, + ), + ], ), - LenraOverlayEntry( - showOverlay: showOverlay, - child: SizedBox( - width: double.infinity, - height: double.infinity, - child: Container( - child: Center( - child: Container( - color: LenraColorThemeData.greyNature, + if (!removeOverlays) ...[ + LenraOverlayEntry( + showOverlay: showOverlay, + child: SizedBox( + width: double.infinity, + height: double.infinity, + child: Container( + child: Center( + child: Container( + color: LenraColorThemeData.greyNature, + child: LenraFlex( + direction: Axis.vertical, + padding: EdgeInsets.all(2), + spacing: 2, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + LenraText(text: "This is an overlay entry"), + LenraButton( + text: "Close", + onPressed: () { + setState(() { + showOverlay = false; + }); + }, + ), + ], + ), + ), + ), + ), + ), + ), + LenraOverlayEntry( + showOverlay: showOverlay2, + child: SizedBox( + width: double.infinity, + height: double.infinity, + child: Container( + color: LenraColorThemeData.greyLight, + child: Center( child: LenraFlex( - direction: Axis.vertical, spacing: 2, + direction: Axis.vertical, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - LenraText(text: "This is an overlay entry"), + LenraText(text: "This is an overlay."), + LenraText(text: "You can close it by clicking on the button."), LenraButton( text: "Close", onPressed: () { setState(() { - showOverlay = false; + showOverlay2 = false; }); }, ), @@ -63,37 +112,7 @@ class _OverlayEntryExampleState extends State { ), ), ), - ), - LenraOverlayEntry( - showOverlay: showOverlay3, - child: SizedBox( - width: double.infinity, - height: double.infinity, - child: Container( - color: LenraColorThemeData.greyLight, - child: Center( - child: LenraFlex( - spacing: 2, - direction: Axis.vertical, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - LenraText(text: "This is an overlay."), - LenraText(text: "You can close it by clicking on the button."), - LenraButton( - text: "Close", - onPressed: () { - setState(() { - showOverlay3 = false; - }); - }, - ), - ], - ), - ), - ), - ), - ), + ] ], ), ); diff --git a/lib/layout/lenra_overlay_entry.dart b/lib/layout/lenra_overlay_entry.dart index 3cf03f4..be544c9 100644 --- a/lib/layout/lenra_overlay_entry.dart +++ b/lib/layout/lenra_overlay_entry.dart @@ -34,7 +34,7 @@ class _LenraOverlayEntryState extends State { @override void deactivate() { super.deactivate(); - if (overlayEntry.mounted) { + if (widget.showOverlay == true && overlayEntry.mounted) { removeOverlay(); } } From cee93d8fa028386d40c7b4cab71a41ae33c42fdd Mon Sep 17 00:00:00 2001 From: Jonas Martinez <36544012+jonas-martinez@users.noreply.github.com> Date: Fri, 6 May 2022 15:10:07 +0200 Subject: [PATCH 2/2] Update lib/layout/lenra_overlay_entry.dart Co-authored-by: Shiipou --- lib/layout/lenra_overlay_entry.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/layout/lenra_overlay_entry.dart b/lib/layout/lenra_overlay_entry.dart index be544c9..0e7ce42 100644 --- a/lib/layout/lenra_overlay_entry.dart +++ b/lib/layout/lenra_overlay_entry.dart @@ -34,7 +34,7 @@ class _LenraOverlayEntryState extends State { @override void deactivate() { super.deactivate(); - if (widget.showOverlay == true && overlayEntry.mounted) { + if (widget.showOverlay && overlayEntry.mounted) { removeOverlay(); } }