Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inesa/icon and icon content #4305

Merged
merged 15 commits into from
Nov 4, 2024
36 changes: 23 additions & 13 deletions packages/flet/lib/src/controls/cupertino_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,38 @@ class _CupertinoNavigationBarControlState
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 =
var iconStr = parseIcon(destView.control.attrString("icon"));
var iconCtrls = destView.children
.where((c) => c.name == "icon" && c.isVisible);
// if no control provided in "icon" property, replace iconCtrls with control provided in icon_content, if any
// the line below needs to be deleted after icon_content is deprecated
iconCtrls = iconCtrls.isEmpty? destView.children
.where((c) => c.name == "icon_content" && c.isVisible) : iconCtrls;

var selectedIconStr =
parseIcon(destView.control.attrString("selectedIcon"));
var selectedIconContentCtrls = destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible);
var selectedIconCtrls = destView.children
.where((c) => c.name == "selected_icon" && c.isVisible);
// if no control provided in "selected_icon" property, replace selectedIconCtrls with control provided in selected_icon_content, if any
// the line below needs to be deleted after selected_icon_content is deprecated
selectedIconCtrls = selectedIconCtrls.isEmpty? destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible): selectedIconCtrls;

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,
icon: iconCtrls.isNotEmpty
? createControl(destView.control, iconCtrls.first.id,
destinationDisabled,
parentAdaptive: widget.parentAdaptive)
: Icon(icon),
activeIcon: selectedIconContentCtrls.isNotEmpty
: Icon(iconStr),
activeIcon: selectedIconCtrls.isNotEmpty
? createControl(destView.control,
selectedIconContentCtrls.first.id, destinationDisabled,
selectedIconCtrls.first.id, destinationDisabled,
parentAdaptive: widget.parentAdaptive)
: selectedIcon != null
? Icon(selectedIcon)
: selectedIconStr != null
? Icon(selectedIconStr)
: null,
label: label);
}).toList());
Expand Down
26 changes: 14 additions & 12 deletions packages/flet/lib/src/controls/dropdown.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../utils/icons.dart';
import 'package:flutter/material.dart';

import '../flet_control_backend.dart';
Expand Down Expand Up @@ -72,8 +73,9 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {

var textSize = widget.control.attrDouble("textSize");
var alignment = parseAlignment(widget.control, "alignment");
var iconCtrl =
widget.children.where((c) => c.name == "icon" && c.isVisible);
var selectIconStr = parseIcon(widget.control.attrString("selectIcon"));
var selectIconCtrl =
widget.children.where((c) => c.name == "selectIcon" && c.isVisible);
var hintCtrl =
widget.children.where((c) => c.name == "hint" && c.isVisible);
var disabledHintCtrl = widget.children
Expand All @@ -82,10 +84,10 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
var color = widget.control.attrColor("color", context);
var focusedColor = widget.control.attrColor("focusedColor", context);
var bgcolor = widget.control.attrColor("bgcolor", context);
var iconEnabledColor =
widget.control.attrColor("iconEnabledColor", context);
var iconDisabledColor =
widget.control.attrColor("iconDisabledColor", context);
var selectIconEnabledColor =
widget.control.attrColor("selectIconEnabledColor", context);
var selectIconDisabledColor =
widget.control.attrColor("selectIconDisabledColor", context);

TextStyle? textStyle =
parseTextStyle(Theme.of(context), widget.control, "textStyle");
Expand Down Expand Up @@ -183,15 +185,15 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
padding: parseEdgeInsets(widget.control, "padding"),
itemHeight: widget.control.attrDouble("itemHeight"),
menuMaxHeight: widget.control.attrDouble("maxMenuHeight"),
iconEnabledColor: iconEnabledColor,
iconDisabledColor: iconDisabledColor,
iconSize: widget.control.attrDouble("iconSize", 24.0)!,
iconEnabledColor: selectIconEnabledColor,
iconDisabledColor: selectIconDisabledColor,
iconSize: widget.control.attrDouble("selectIconSize", 24.0)!,
borderRadius: borderRadius,
alignment: alignment ?? AlignmentDirectional.centerStart,
isExpanded: widget.control.attrBool("optionsFillHorizontally", false)!,
icon: iconCtrl.isNotEmpty
? createControl(widget.control, iconCtrl.first.id, disabled)
: null,
icon: selectIconCtrl.isNotEmpty
? createControl(widget.control, selectIconCtrl.first.id, disabled)
: selectIconStr != null? Icon(selectIconStr): null,
hint: hintCtrl.isNotEmpty
? createControl(widget.control, hintCtrl.first.id, disabled)
: null,
Expand Down
36 changes: 21 additions & 15 deletions packages/flet/lib/src/controls/navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,37 @@ class _NavigationBarControlState extends State<NavigationBarControl>
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 =
var iconStr = parseIcon(destView.control.attrString("icon"));
var iconCtrls = destView.children
.where((c) => c.name == "icon" && c.isVisible);
// if no control provided in "icon" property, replace iconCtrls with control provided in icon_content, if any
// the line below needs to be deleted after icon_content is deprecated
iconCtrls = iconCtrls.isEmpty? destView.children
.where((c) => c.name == "icon_content" && c.isVisible) : iconCtrls;
var selectedIconStr =
parseIcon(destView.control.attrString("selectedIcon"));
var selectedIconContentCtrls = destView.children.where(
(c) => c.name == "selected_icon_content" && c.isVisible);
var selectedIconCtrls = destView.children
.where((c) => c.name == "selected_icon" && c.isVisible);
// if no control provided in "selected_icon" property, replace selectedIconCtrls with control provided in selected_icon_content, if any
// the line below needs to be deleted after selected_icon_content is deprecated
selectedIconCtrls = selectedIconCtrls.isEmpty? destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible): selectedIconCtrls;
var destinationDisabled = disabled || destView.control.isDisabled;
var destinationAdaptive = destView.control.isAdaptive ?? adaptive;
return NavigationDestination(
enabled: !destinationDisabled,
tooltip: destView.control.attrString("tooltip"),
icon: iconContentCtrls.isNotEmpty
? createControl(destView.control,
iconContentCtrls.first.id, destinationDisabled,
parentAdaptive: destinationAdaptive)
: Icon(icon),
selectedIcon: selectedIconContentCtrls.isNotEmpty
icon: iconCtrls.isNotEmpty? createControl(destView.control,
iconCtrls.first.id, destinationDisabled,
parentAdaptive: destinationAdaptive): Icon(iconStr),
selectedIcon: selectedIconCtrls.isNotEmpty
? createControl(
destView.control,
selectedIconContentCtrls.first.id,
selectedIconCtrls.first.id,
destinationDisabled,
parentAdaptive: destinationAdaptive)
: selectedIcon != null
? Icon(selectedIcon)
: selectedIconStr != null
? Icon(selectedIconStr)
: null,
label: label);
}).toList());
Expand Down
34 changes: 22 additions & 12 deletions packages/flet/lib/src/controls/navigation_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,37 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl>
.map((c) => c.id), (content, viewModel) {
List<Widget> children = viewModel.controlViews.map((destView) {
if (destView.control.type == "navigationdrawerdestination") {
var iconContentCtrls = destView.children
.where((c) => c.name == "icon_content" && c.isVisible);
var selectedIcon =
var iconStr = parseIcon(destView.control.attrString("icon"));
var iconCtrls = destView.children
.where((c) => c.name == "icon" && c.isVisible);
// if no control provided in "icon" property, replace iconCtrls with control provided in icon_content, if any
// the line below needs to be deleted after icon_content is deprecated
iconCtrls = iconCtrls.isEmpty? destView.children
.where((c) => c.name == "icon_content" && c.isVisible) : iconCtrls;

var selectedIconStr =
parseIcon(destView.control.attrString("selectedIcon"));
var selectedIconContentCtrls = destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible);
var selectedIconCtrls = destView.children
.where((c) => c.name == "selected_icon" && c.isVisible);
// if no control provided in "selected_icon" property, replace selectedIconCtrls with control provided in selected_icon_content, if any
// the line below needs to be deleted after selected_icon_content is deprecated
selectedIconCtrls = selectedIconCtrls.isEmpty? destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible): selectedIconCtrls;
return NavigationDrawerDestination(
enabled: !(disabled || destView.control.isDisabled),
backgroundColor: destView.control.attrColor("bgColor", context),
icon: iconContentCtrls.isNotEmpty
icon: iconCtrls.isNotEmpty
? createControl(
destView.control, iconContentCtrls.first.id, disabled,
destView.control, iconCtrls.first.id, disabled,
parentAdaptive: widget.parentAdaptive)
: Icon(parseIcon(destView.control.attrString("icon"))),
: Icon(iconStr),
label: Text(destView.control.attrString("label", "")!),
selectedIcon: selectedIconContentCtrls.isNotEmpty
selectedIcon: selectedIconCtrls.isNotEmpty
? createControl(destView.control,
selectedIconContentCtrls.first.id, disabled,
selectedIconCtrls.first.id, disabled,
parentAdaptive: widget.parentAdaptive)
: selectedIcon != null
? Icon(selectedIcon)
: selectedIconStr != null
? Icon(selectedIconStr)
: null,
);
} else {
Expand Down
36 changes: 22 additions & 14 deletions packages/flet/lib/src/controls/navigation_rail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,22 @@ class _NavigationRailControlState extends State<NavigationRailControl>
var labelContentCtrls = destView.children
.where((c) => c.name == "label_content" && c.isVisible);

var icon = parseIcon(destView.control.attrString("icon"));
var iconContentCtrls = destView.children
.where((c) => c.name == "icon_content" && c.isVisible);

var selectedIcon =
var iconStr = parseIcon(destView.control.attrString("icon"));
var iconCtrls = destView.children
.where((c) => c.name == "icon" && c.isVisible);
// if no control provided in "icon" property, replace iconCtrls with control provided in icon_content, if any
// the line below needs to be deleted after icon_content is deprecated
iconCtrls = iconCtrls.isEmpty? destView.children
.where((c) => c.name == "icon_content" && c.isVisible) : iconCtrls;

var selectedIconStr =
parseIcon(destView.control.attrString("selectedIcon"));
var selectedIconContentCtrls = destView.children
.where((c) => c.name == "selected_icon_content");
var selectedIconCtrls = destView.children
.where((c) => c.name == "selected_icon" && c.isVisible);
// if no control provided in "selected_icon" property, replace selectedIconCtrls with control provided in selected_icon_content, if any
// the line below needs to be deleted after selected_icon_content is deprecated
selectedIconCtrls = selectedIconCtrls.isEmpty? destView.children
.where((c) => c.name == "selected_icon_content" && c.isVisible): selectedIconCtrls;

return NavigationRailDestination(
disabled: disabled || destView.control.isDisabled,
Expand All @@ -136,17 +144,17 @@ class _NavigationRailControlState extends State<NavigationRailControl>
destView.control.attrColor("indicatorColor", context),
indicatorShape:
parseOutlinedBorder(destView.control, "indicatorShape"),
icon: iconContentCtrls.isNotEmpty
icon: iconCtrls.isNotEmpty
? createControl(destView.control,
iconContentCtrls.first.id, disabled,
iconCtrls.first.id, disabled,
parentAdaptive: widget.parentAdaptive)
: Icon(icon),
selectedIcon: selectedIconContentCtrls.isNotEmpty
: Icon(iconStr),
selectedIcon: selectedIconCtrls.isNotEmpty
? createControl(destView.control,
selectedIconContentCtrls.first.id, disabled,
selectedIconCtrls.first.id, disabled,
parentAdaptive: widget.parentAdaptive)
: selectedIcon != null
? Icon(selectedIcon)
: selectedIconStr != null
? Icon(selectedIconStr)
: null,
label: labelContentCtrls.isNotEmpty
? createControl(destView.control,
Expand Down
Loading