Skip to content

Commit

Permalink
fix: NavigationBarDestination.disabled has no visual effect (#4073)
Browse files Browse the repository at this point in the history
* initial commit

* NavigationBarDestination: show tooltip only if one is specified
  • Loading branch information
ndonkoHenri authored Oct 17, 2024
1 parent f612ac0 commit 3fc6118
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
19 changes: 9 additions & 10 deletions packages/flet/lib/src/controls/cupertino_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class _CupertinoNavigationBarControlState
extends State<CupertinoNavigationBarControl> with FletStoreMixin {
int _selectedIndex = 0;

bool get disabled => widget.control.isDisabled || widget.parentDisabled;

void _onTap(int index) {
_selectedIndex = index;
debugPrint("Selected index: $_selectedIndex");
Expand All @@ -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)
Expand Down
43 changes: 19 additions & 24 deletions packages/flet/lib/src/controls/navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -49,8 +50,7 @@ class _NavigationBarControlState extends State<NavigationBarControl>
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)) {
Expand All @@ -68,22 +68,16 @@ class _NavigationBarControlState extends State<NavigationBarControl>
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:
Expand All @@ -95,31 +89,32 @@ class _NavigationBarControlState extends State<NavigationBarControl>
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,
Expand Down
4 changes: 4 additions & 0 deletions packages/flet/lib/src/models/control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)!;
}
Expand Down

0 comments on commit 3fc6118

Please sign in to comment.