Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit fb2db33

Browse files
author
Yuncong Zhang
committed
[1.5.4] Upgrade most of material.
1 parent 7ed8c58 commit fb2db33

8 files changed

+323
-71
lines changed

Runtime/material/dropdown.cs

Lines changed: 107 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,72 @@ public override Color barrierColor {
330330

331331
public override Widget buildPage(BuildContext context, Animation<float> animation,
332332
Animation<float> secondaryAnimation) {
333+
return new LayoutBuilder(
334+
builder: (ctx, constraints) => {
335+
return new _DropdownRoutePage<T>(
336+
route: this,
337+
constraints: constraints,
338+
items: this.items,
339+
padding: this.padding,
340+
buttonRect: this.buttonRect,
341+
selectedIndex: this.selectedIndex,
342+
elevation: this.elevation,
343+
theme: this.theme,
344+
style: this.style
345+
);
346+
}
347+
);
348+
}
349+
350+
internal void _dismiss() {
351+
this.navigator?.removeRoute(this);
352+
}
353+
}
354+
355+
class _DropdownRoutePage<T> : StatelessWidget where T : class {
356+
public _DropdownRoutePage(
357+
Key key = null,
358+
_DropdownRoute<T> route = null,
359+
BoxConstraints constraints = null,
360+
List<DropdownMenuItem<T>> items = null,
361+
EdgeInsets padding = null,
362+
Rect buttonRect = null,
363+
int? selectedIndex = null,
364+
int elevation = 0,
365+
ThemeData theme = null,
366+
TextStyle style = null
367+
) : base(key: key) {
368+
this.route = route;
369+
this.constraints = constraints;
370+
this.items = items;
371+
this.padding = padding;
372+
this.buttonRect = buttonRect;
373+
this.selectedIndex = selectedIndex;
374+
this.elevation = elevation;
375+
this.theme = theme;
376+
this.style = style;
377+
}
378+
379+
public readonly _DropdownRoute<T> route;
380+
public readonly BoxConstraints constraints;
381+
public readonly List<DropdownMenuItem<T>> items;
382+
public readonly EdgeInsets padding;
383+
public readonly Rect buttonRect;
384+
public readonly int? selectedIndex;
385+
public readonly int elevation;
386+
public readonly ThemeData theme;
387+
public readonly TextStyle style;
388+
389+
public override Widget build(BuildContext context) {
333390
D.assert(WidgetsD.debugCheckHasDirectionality(context));
334-
float screenHeight = MediaQuery.of(context).size.height;
335-
float maxMenuHeight = screenHeight - 2.0f * DropdownConstants._kMenuItemHeight;
391+
float availableHeight = this.constraints.maxHeight;
392+
float maxMenuHeight = availableHeight - 2.0f * DropdownConstants._kMenuItemHeight;
336393

337394
float buttonTop = this.buttonRect.top;
338-
float buttonBottom = this.buttonRect.bottom;
395+
float buttonBottom = Mathf.Min(this.buttonRect.bottom, availableHeight);
339396

340397
float topLimit = Mathf.Min(DropdownConstants._kMenuItemHeight, buttonTop);
341-
float bottomLimit = Mathf.Max(screenHeight - DropdownConstants._kMenuItemHeight, buttonBottom);
398+
float bottomLimit = Mathf.Max(availableHeight - DropdownConstants._kMenuItemHeight, buttonBottom);
342399

343400
float? selectedItemOffset = this.selectedIndex * DropdownConstants._kMenuItemHeight +
344401
Constants.kMaterialListPadding.top;
@@ -361,15 +418,15 @@ public override Widget buildPage(BuildContext context, Animation<float> animatio
361418
menuTop = menuBottom - menuHeight;
362419
}
363420

364-
if (this.scrollController == null) {
421+
if (this.route.scrollController == null) {
365422
float scrollOffset = preferredMenuHeight > maxMenuHeight
366423
? Mathf.Max(0.0f, selectedItemOffset ?? 0.0f - (buttonTop - (menuTop ?? 0.0f)))
367424
: 0.0f;
368-
this.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
425+
this.route.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
369426
}
370427

371428
Widget menu = new _DropdownMenu<T>(
372-
route: this,
429+
route: this.route,
373430
padding: this.padding
374431
);
375432

@@ -397,10 +454,6 @@ public override Widget buildPage(BuildContext context, Animation<float> animatio
397454
)
398455
);
399456
}
400-
401-
public void _dismiss() {
402-
this.navigator?.removeRoute(this);
403-
}
404457
}
405458

406459
public class DropdownMenuItem<T> : StatelessWidget where T : class {
@@ -454,6 +507,10 @@ public DropdownButton(
454507
ValueChanged<T> onChanged = null,
455508
int elevation = 8,
456509
TextStyle style = null,
510+
Widget underline = null,
511+
Widget icon = null,
512+
Color iconDisabledColor = null,
513+
Color iconEnabledColor = null,
457514
float iconSize = 24.0f,
458515
bool isDense = false,
459516
bool isExpanded = false
@@ -469,6 +526,10 @@ public DropdownButton(
469526
this.onChanged = onChanged;
470527
this.elevation = elevation;
471528
this.style = style;
529+
this.underline = underline;
530+
this.icon = icon;
531+
this.iconDisabledColor = iconDisabledColor;
532+
this.iconEnabledColor = iconEnabledColor;
472533
this.iconSize = iconSize;
473534
this.isDense = isDense;
474535
this.isExpanded = isExpanded;
@@ -488,6 +549,14 @@ public DropdownButton(
488549

489550
public readonly TextStyle style;
490551

552+
public readonly Widget underline;
553+
554+
public readonly Widget icon;
555+
556+
public readonly Color iconDisabledColor;
557+
558+
public readonly Color iconEnabledColor;
559+
491560
public readonly float iconSize;
492561

493562
public readonly bool isDense;
@@ -606,24 +675,34 @@ void _handleTap() {
606675
}
607676
}
608677

609-
Color _downArrowColor {
678+
Color _iconColor {
610679
get {
611680
if (this._enabled) {
612-
if (Theme.of(this.context).brightness == Brightness.light) {
613-
return Colors.grey.shade700;
681+
if (this.widget.iconEnabledColor != null) {
682+
return this.widget.iconEnabledColor;
614683
}
615-
else {
616-
return Colors.white70;
684+
685+
switch (Theme.of(this.context).brightness) {
686+
case Brightness.light:
687+
return Colors.grey.shade700;
688+
case Brightness.dark:
689+
return Colors.white70;
617690
}
618691
}
619692
else {
620-
if (Theme.of(this.context).brightness == Brightness.light) {
621-
return Colors.grey.shade400;
693+
if (this.widget.iconDisabledColor != null) {
694+
return this.widget.iconDisabledColor;
622695
}
623-
else {
624-
return Colors.white10;
696+
697+
switch (Theme.of(this.context).brightness) {
698+
case Brightness.light:
699+
return Colors.grey.shade400;
700+
case Brightness.dark:
701+
return Colors.white10;
625702
}
626703
}
704+
D.assert(false);
705+
return null;
627706
}
628707
}
629708

@@ -661,6 +740,7 @@ public override Widget build(BuildContext context) {
661740
children: items
662741
);
663742

743+
Icon defaultIcon = new Icon(Icons.arrow_drop_down);
664744
Widget result = new DefaultTextStyle(
665745
style: this._textStyle,
666746
child: new Container(
@@ -671,9 +751,12 @@ public override Widget build(BuildContext context) {
671751
mainAxisSize: MainAxisSize.min,
672752
children: new List<Widget> {
673753
this.widget.isExpanded ? new Expanded(child: innerItemsWidget) : (Widget) innerItemsWidget,
674-
new Icon(Icons.arrow_drop_down,
675-
size: this.widget.iconSize,
676-
color: this._downArrowColor
754+
new IconTheme(
755+
data: new IconThemeData(
756+
color: this._iconColor,
757+
size: this.widget.iconSize
758+
),
759+
child: this.widget.icon ?? defaultIcon
677760
)
678761
}
679762
)
@@ -689,7 +772,7 @@ public override Widget build(BuildContext context) {
689772
left: 0.0f,
690773
right: 0.0f,
691774
bottom: bottom,
692-
child: new Container(
775+
child: this.widget.underline ?? new Container(
693776
height: 1.0f,
694777
decoration: new BoxDecoration(
695778
border: new Border(

Runtime/material/expansion_panel.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,33 @@ public class ExpansionPanel {
8787
public ExpansionPanel(
8888
ExpansionPanelHeaderBuilder headerBuilder = null,
8989
Widget body = null,
90-
bool isExpanded = false) {
90+
bool isExpanded = false,
91+
bool canTapOnHeader = false) {
9192
D.assert(headerBuilder != null);
9293
D.assert(body != null);
9394
this.headerBuilder = headerBuilder;
9495
this.body = body;
9596
this.isExpanded = isExpanded;
97+
this.canTapOnHeader = false;
9698
}
9799

98100
public readonly ExpansionPanelHeaderBuilder headerBuilder;
99101

100102
public readonly Widget body;
101103

102104
public readonly bool isExpanded;
105+
106+
public readonly bool canTapOnHeader;
103107
}
104108

105109

106110
public class ExpansionPanelRadio : ExpansionPanel {
107111
public ExpansionPanelRadio(
108112
object value = null,
109113
ExpansionPanelHeaderBuilder headerBuilder = null,
110-
Widget body = null) : base(body: body, headerBuilder: headerBuilder) {
114+
Widget body = null,
115+
bool canTapOnHeader = false)
116+
: base(body: body, headerBuilder: headerBuilder, canTapOnHeader: canTapOnHeader) {
111117
D.assert(headerBuilder != null);
112118
D.assert(body != null);
113119
D.assert(value != null);
@@ -263,6 +269,10 @@ public override Widget build(BuildContext context) {
263269
}
264270

265271
ExpansionPanel child = this.widget.children[index];
272+
Widget headerWidget = child.headerBuilder(
273+
context,
274+
this._isChildExpanded(index)
275+
);
266276
Row header = new Row(
267277
children: new List<Widget> {
268278
new Expanded(
@@ -273,9 +283,7 @@ public override Widget build(BuildContext context) {
273283
child: new ConstrainedBox(
274284
constraints: new BoxConstraints(
275285
minHeight: ExpansionPanelUtils._kPanelHeaderCollapsedHeight),
276-
child: child.headerBuilder(
277-
context,
278-
this._isChildExpanded(index))
286+
child: headerWidget
279287
)
280288
)
281289
),
@@ -284,7 +292,11 @@ public override Widget build(BuildContext context) {
284292
child: new ExpandIcon(
285293
isExpanded: this._isChildExpanded(index),
286294
padding: EdgeInsets.all(16.0f),
287-
onPressed: (bool isExpanded) => this._handlePressed(isExpanded, expandIndex)
295+
onPressed: !child.canTapOnHeader
296+
? (ValueChanged<bool>) ((bool isExpanded) => {
297+
this._handlePressed(isExpanded, expandIndex);
298+
})
299+
: null
288300
)
289301
)
290302
}
@@ -294,7 +306,13 @@ public override Widget build(BuildContext context) {
294306
key: new _SaltedKey<BuildContext, int>(context, index * 2),
295307
child: new Column(
296308
children: new List<Widget> {
297-
header,
309+
child.canTapOnHeader
310+
? (Widget) new InkWell(
311+
onTap: () =>
312+
this._handlePressed(this._isChildExpanded(expandIndex), expandIndex),
313+
child: header
314+
)
315+
: header,
298316
new AnimatedCrossFade(
299317
firstChild: new Container(height: 0.0f),
300318
secondChild: child.body,

0 commit comments

Comments
 (0)