From 7ff316f657c79090077ca6c870496ca2237a5d02 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 1 Oct 2024 12:21:55 +0200 Subject: [PATCH 1/2] initial commit --- .../controls/cupertino_navigation_bar.dart | 19 ++++---- .../flet/lib/src/controls/navigation_bar.dart | 43 ++++++++----------- packages/flet/lib/src/models/control.dart | 4 ++ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/flet/lib/src/controls/cupertino_navigation_bar.dart b/packages/flet/lib/src/controls/cupertino_navigation_bar.dart index 6b884ce88..1091e4145 100644 --- a/packages/flet/lib/src/controls/cupertino_navigation_bar.dart +++ b/packages/flet/lib/src/controls/cupertino_navigation_bar.dart @@ -34,6 +34,8 @@ class _CupertinoNavigationBarControlState extends State with FletStoreMixin { int _selectedIndex = 0; + bool get disabled => widget.control.isDisabled || widget.parentDisabled; + void _onTap(int index) { _selectedIndex = index; debugPrint("Selected index: $_selectedIndex"); @@ -47,49 +49,46 @@ class _CupertinoNavigationBarControlState Widget build(BuildContext context) { debugPrint("CupertinoNavigationBarControl build: ${widget.control.id}"); - bool disabled = widget.control.isDisabled || widget.parentDisabled; var selectedIndex = widget.control.attrInt("selectedIndex", 0)!; if (_selectedIndex != selectedIndex) { _selectedIndex = selectedIndex; } - var navBar = withControls( widget.children .where((c) => c.isVisible && c.name == null) .map((c) => c.id), (content, viewModel) { return CupertinoTabBar( backgroundColor: widget.control.attrColor("bgColor", context), - activeColor: widget.control.attrColor("activeColor", context), + activeColor: widget.control.attrColor("activeColor", context) ?? + widget.control.attrColor("indicatorColor", context), inactiveColor: widget.control.attrColor("inactiveColor", context) ?? CupertinoColors.inactiveGray, iconSize: widget.control.attrDouble("iconSize", 30.0)!, currentIndex: _selectedIndex, border: parseBorder(Theme.of(context), widget.control, "border"), - onTap: _onTap, + onTap: disabled ? null : _onTap, items: viewModel.controlViews.map((destView) { var label = destView.control.attrString("label", "")!; - var icon = parseIcon(destView.control.attrString("icon")); var iconContentCtrls = destView.children .where((c) => c.name == "icon_content" && c.isVisible); - var selectedIcon = parseIcon(destView.control.attrString("selectedIcon")); var selectedIconContentCtrls = destView.children .where((c) => c.name == "selected_icon_content" && c.isVisible); - + var destinationDisabled = disabled || destView.control.isDisabled; return BottomNavigationBarItem( tooltip: destView.control.attrString("tooltip", "")!, backgroundColor: widget.control.attrColor("bgColor", context), icon: iconContentCtrls.isNotEmpty - ? createControl( - destView.control, iconContentCtrls.first.id, disabled, + ? createControl(destView.control, iconContentCtrls.first.id, + destinationDisabled, parentAdaptive: widget.parentAdaptive) : Icon(icon), activeIcon: selectedIconContentCtrls.isNotEmpty ? createControl(destView.control, - selectedIconContentCtrls.first.id, disabled, + selectedIconContentCtrls.first.id, destinationDisabled, parentAdaptive: widget.parentAdaptive) : selectedIcon != null ? Icon(selectedIcon) diff --git a/packages/flet/lib/src/controls/navigation_bar.dart b/packages/flet/lib/src/controls/navigation_bar.dart index bfca05aa0..0f3d55073 100644 --- a/packages/flet/lib/src/controls/navigation_bar.dart +++ b/packages/flet/lib/src/controls/navigation_bar.dart @@ -6,6 +6,7 @@ import '../utils/borders.dart'; import '../utils/colors.dart'; import '../utils/icons.dart'; import '../utils/others.dart'; +import '../utils/time.dart'; import 'create_control.dart'; import 'cupertino_navigation_bar.dart'; import 'flet_store_mixin.dart'; @@ -49,8 +50,7 @@ class _NavigationBarControlState extends State debugPrint("NavigationBarControl build: ${widget.control.id}"); return withPagePlatform((context, platform) { - bool? adaptive = - widget.control.attrBool("adaptive") ?? widget.parentAdaptive; + bool? adaptive = widget.control.isAdaptive ?? widget.parentAdaptive; if (adaptive == true && (platform == TargetPlatform.iOS || platform == TargetPlatform.macOS)) { @@ -68,22 +68,16 @@ class _NavigationBarControlState extends State if (_selectedIndex != selectedIndex) { _selectedIndex = selectedIndex; } - var animationDuration = widget.control.attrInt("animationDuration"); - - NavigationDestinationLabelBehavior? labelBehavior = - parseNavigationDestinationLabelBehavior( - widget.control.attrString("labelBehavior")); - var navBar = withControls( widget.children .where((c) => c.isVisible && c.name == null) .map((c) => c.id), (content, viewModel) { return NavigationBar( - labelBehavior: labelBehavior, + labelBehavior: parseNavigationDestinationLabelBehavior( + widget.control.attrString("labelBehavior")), height: widget.control.attrDouble("height"), - animationDuration: animationDuration != null - ? Duration(milliseconds: animationDuration) - : null, + animationDuration: + parseDuration(widget.control, "animationDuration"), elevation: widget.control.attrDouble("elevation"), shadowColor: widget.control.attrColor("shadowColor", context), surfaceTintColor: @@ -95,31 +89,32 @@ class _NavigationBarControlState extends State parseOutlinedBorder(widget.control, "indicatorShape"), backgroundColor: widget.control.attrColor("bgColor", context), selectedIndex: _selectedIndex, - onDestinationSelected: _destinationChanged, + onDestinationSelected: disabled ? null : _destinationChanged, destinations: viewModel.controlViews.map((destView) { var label = destView.control.attrString("label", "")!; - var icon = parseIcon(destView.control.attrString("icon")); var iconContentCtrls = destView.children .where((c) => c.name == "icon_content" && c.isVisible); - var selectedIcon = parseIcon(destView.control.attrString("selectedIcon")); var selectedIconContentCtrls = destView.children.where( (c) => c.name == "selected_icon_content" && c.isVisible); - + var destinationDisabled = disabled || destView.control.isDisabled; + var destinationAdaptive = destView.control.isAdaptive ?? adaptive; return NavigationDestination( - enabled: !disabled || !destView.control.isDisabled, - tooltip: destView.control.attrString("tooltip", "")!, + enabled: !destinationDisabled, + tooltip: destView.control.attrString("tooltip"), icon: iconContentCtrls.isNotEmpty - ? createControl( - destView.control, iconContentCtrls.first.id, disabled, - parentAdaptive: adaptive) + ? createControl(destView.control, + iconContentCtrls.first.id, destinationDisabled, + parentAdaptive: destinationAdaptive) : Icon(icon), selectedIcon: selectedIconContentCtrls.isNotEmpty - ? createControl(destView.control, - selectedIconContentCtrls.first.id, disabled, - parentAdaptive: adaptive) + ? createControl( + destView.control, + selectedIconContentCtrls.first.id, + destinationDisabled, + parentAdaptive: destinationAdaptive) : selectedIcon != null ? Icon(selectedIcon) : null, diff --git a/packages/flet/lib/src/models/control.dart b/packages/flet/lib/src/models/control.dart index 792eb051f..31d7e863d 100644 --- a/packages/flet/lib/src/models/control.dart +++ b/packages/flet/lib/src/models/control.dart @@ -46,6 +46,10 @@ class Control extends Equatable { return attrBool("disabled", false)!; } + bool? get isAdaptive { + return attrBool("adaptive"); + } + bool get isVisible { return attrBool("visible", true)!; } From 2555cbba0a7764616884e335283699abd415cd6f Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 1 Oct 2024 12:43:07 +0200 Subject: [PATCH 2/2] NavigationBarDestination: show tooltip only if one is specified --- packages/flet/lib/src/controls/navigation_bar.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flet/lib/src/controls/navigation_bar.dart b/packages/flet/lib/src/controls/navigation_bar.dart index 0f3d55073..5f365ff96 100644 --- a/packages/flet/lib/src/controls/navigation_bar.dart +++ b/packages/flet/lib/src/controls/navigation_bar.dart @@ -103,7 +103,7 @@ class _NavigationBarControlState extends State var destinationAdaptive = destView.control.isAdaptive ?? adaptive; return NavigationDestination( enabled: !destinationDisabled, - tooltip: destView.control.attrString("tooltip"), + tooltip: destView.control.attrString("tooltip") ?? "", icon: iconContentCtrls.isNotEmpty ? createControl(destView.control, iconContentCtrls.first.id, destinationDisabled,