@@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
22
33import '../flet_control_backend.dart' ;
44import '../models/control.dart' ;
5+ import '../utils/animations.dart' ;
56import '../utils/borders.dart' ;
7+ import '../utils/box.dart' ;
68import '../utils/colors.dart' ;
79import '../utils/edge_insets.dart' ;
810import '../utils/others.dart' ;
@@ -73,115 +75,105 @@ class _ChipControlState extends State<ChipControl> {
7375
7476 var labelCtrls =
7577 widget.children.where ((c) => c.name == "label" && c.isVisible);
78+ if (labelCtrls.isEmpty) {
79+ return const ErrorControl ("Chip.label must be provided and visible" );
80+ }
7681 var leadingCtrls =
7782 widget.children.where ((c) => c.name == "leading" && c.isVisible);
7883 var deleteIconCtrls =
7984 widget.children.where ((c) => c.name == "deleteIcon" && c.isVisible);
8085
81- if (labelCtrls.isEmpty) {
82- return const ErrorControl ("Chip.label must be provided and visible" );
83- }
84-
85- double ? clickElevation = widget.control.attrDouble ("clickElevation" );
86- Color ? bgcolor = widget.control.attrColor ("bgcolor" , context);
87- Color ? deleteIconColor =
88- widget.control.attrColor ("deleteIconColor" , context);
89- Color ? disabledColor = widget.control.attrColor ("disabledColor" , context);
90- Color ? surfaceTintColor =
91- widget.control.attrColor ("surfaceTintColor" , context);
92- Color ? selectedShadowColor =
93- widget.control.attrColor ("selectedShadowColor" , context);
94- Color ? shadowColor = widget.control.attrColor ("shadowColor" , context);
95- var color =
96- parseWidgetStateColor (Theme .of (context), widget.control, "color" );
97-
98- BorderSide ? borderSide =
99- parseBorderSide (Theme .of (context), widget.control, "borderSide" );
100- VisualDensity ? visualDensity =
101- parseVisualDensity (widget.control.attrString ("visualDensity" ));
102- Clip clipBehavior =
103- parseClip (widget.control.attrString ("clipBehavior" ), Clip .none)! ;
104-
105- bool onClick = widget.control.attrBool ("onclick" , false )! ;
106- bool onDelete = widget.control.attrBool ("onDelete" , false )! ;
107- bool onSelect = widget.control.attrBool ("onSelect" , false )! ;
86+ var onClick = widget.control.attrBool ("onclick" , false )! ;
87+ var onDelete = widget.control.attrBool ("onDelete" , false )! ;
88+ var onSelect = widget.control.attrBool ("onSelect" , false )! ;
10889
10990 if (onSelect && onClick) {
11091 return const ErrorControl (
11192 "Chip cannot have both on_select and on_click events specified" );
11293 }
11394
114- bool autofocus = widget.control.attrBool ("autofocus" , false )! ;
11595 bool selected = widget.control.attrBool ("selected" , false )! ;
11696 if (_selected != selected) {
11797 _selected = selected;
11898 }
119- bool showCheckmark = widget.control.attrBool ("showCheckmark" , true )! ;
120- String ? deleteButtonTooltip =
121- widget.control.attrString ("deleteButtonTooltip" );
122-
123- var elevation = widget.control.attrDouble ("elevation" );
124-
125- Function ()? onClickHandler = onClick && ! disabled
126- ? () {
127- debugPrint ("Chip ${widget .control .id } clicked!" );
128- widget.backend.triggerControlEvent (widget.control.id, "click" );
129- }
130- : null ;
131-
132- Function ()? onDeleteHandler = onDelete && ! disabled
133- ? () {
134- debugPrint ("Chip ${widget .control .id } deleted!" );
135- widget.backend.triggerControlEvent (widget.control.id, "delete" );
136- }
137- : null ;
13899
139100 return constrainedControl (
140101 context,
141102 InputChip (
142- autofocus: autofocus,
103+ autofocus: widget.control. attrBool ( " autofocus" , false ) ! ,
143104 focusNode: _focusNode,
144105 label: createControl (widget.control, labelCtrls.first.id, disabled,
145106 parentAdaptive: widget.parentAdaptive),
146107 avatar: leadingCtrls.isNotEmpty
147108 ? createControl (widget.control, leadingCtrls.first.id, disabled,
148109 parentAdaptive: widget.parentAdaptive)
149110 : null ,
150- backgroundColor: bgcolor,
111+ backgroundColor: widget.control. attrColor ( " bgcolor" , context) ,
151112 checkmarkColor: widget.control.attrColor ("checkColor" , context),
152113 selected: _selected,
153- showCheckmark: showCheckmark,
154- deleteButtonTooltipMessage: deleteButtonTooltip,
155- onPressed: onClickHandler,
156- onDeleted: onDeleteHandler,
157- onSelected: onSelect && ! disabled
158- ? (bool selected) {
159- _onSelect (selected);
160- }
161- : null ,
114+ showCheckmark: widget.control.attrBool ("showCheckmark" , true )! ,
115+ deleteButtonTooltipMessage:
116+ widget.control.attrString ("deleteButtonTooltip" ),
162117 deleteIcon: deleteIconCtrls.isNotEmpty
163118 ? createControl (
164119 widget.control, deleteIconCtrls.first.id, disabled,
165120 parentAdaptive: widget.parentAdaptive)
166121 : null ,
167- deleteIconColor: deleteIconColor,
168- disabledColor: disabledColor,
169- elevation: elevation,
122+ deleteIconColor: widget.control. attrColor ( " deleteIconColor" , context) ,
123+ disabledColor: widget.control. attrColor ( " disabledColor" , context) ,
124+ elevation: widget.control. attrDouble ( " elevation" ) ,
170125 isEnabled: ! disabled,
171126 padding: parseEdgeInsets (widget.control, "padding" ),
172127 labelPadding: parseEdgeInsets (widget.control, "labelPadding" ),
173128 labelStyle:
174129 parseTextStyle (Theme .of (context), widget.control, "labelStyle" ),
175130 selectedColor: widget.control.attrColor ("selectedColor" , context),
176- selectedShadowColor: selectedShadowColor,
177- shadowColor: shadowColor,
131+ selectedShadowColor:
132+ widget.control.attrColor ("selectedShadowColor" , context),
133+ shadowColor: widget.control.attrColor ("shadowColor" , context),
178134 shape: parseOutlinedBorder (widget.control, "shape" ),
179- color: color,
180- surfaceTintColor: surfaceTintColor,
181- pressElevation: clickElevation,
182- side: borderSide,
183- clipBehavior: clipBehavior,
184- visualDensity: visualDensity,
135+ color:
136+ parseWidgetStateColor (Theme .of (context), widget.control, "color" ),
137+ surfaceTintColor:
138+ widget.control.attrColor ("surfaceTintColor" , context),
139+ pressElevation: widget.control.attrDouble ("clickElevation" ),
140+ side:
141+ parseBorderSide (Theme .of (context), widget.control, "borderSide" ),
142+ clipBehavior:
143+ parseClip (widget.control.attrString ("clipBehavior" ), Clip .none)! ,
144+ visualDensity:
145+ parseVisualDensity (widget.control.attrString ("visualDensity" )),
146+ avatarBoxConstraints:
147+ parseBoxConstraints (widget.control, "avatarSizeConstraints" ),
148+ deleteIconBoxConstraints:
149+ parseBoxConstraints (widget.control, "deleteIconSizeConstraints" ),
150+ chipAnimationStyle: ChipAnimationStyle (
151+ enableAnimation:
152+ parseAnimationStyle (widget.control, "enableAnimationStyle" ),
153+ selectAnimation:
154+ parseAnimationStyle (widget.control, "selectAnimationStyle" ),
155+ avatarDrawerAnimation: parseAnimationStyle (
156+ widget.control, "avatarDrawerAnimationStyle" ),
157+ deleteDrawerAnimation: parseAnimationStyle (
158+ widget.control, "deleteDrawerAnimationStyle" ),
159+ ),
160+ onPressed: onClick && ! disabled
161+ ? () {
162+ widget.backend
163+ .triggerControlEvent (widget.control.id, "click" );
164+ }
165+ : null ,
166+ onDeleted: onDelete && ! disabled
167+ ? () {
168+ widget.backend
169+ .triggerControlEvent (widget.control.id, "delete" );
170+ }
171+ : null ,
172+ onSelected: onSelect && ! disabled
173+ ? (bool selected) {
174+ _onSelect (selected);
175+ }
176+ : null ,
185177 ),
186178 widget.parent,
187179 widget.control);
0 commit comments