xingwei.zhu
4 年前
当前提交
c1269e1c
共有 7 个文件被更改,包括 753 次插入 和 310 次删除
-
379Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/reorderable_list_demo.cs
-
8Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demo.cs
-
244Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs
-
1com.unity.uiwidgets/Runtime/material/radio.cs
-
1com.unity.uiwidgets/Runtime/material/switch.cs
-
222Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/scrollable_tabs_demo.cs
-
208Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/selection_controls_demo.cs
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using uiwidgets; |
|||
using UIWidgetsGallery.gallery; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.demo.material |
|||
{ |
|||
internal enum TabsDemoStyle |
|||
{ |
|||
iconsAndText, |
|||
iconsOnly, |
|||
textOnly |
|||
} |
|||
|
|||
internal class _Page |
|||
{ |
|||
public _Page(IconData icon = null, string text = null) |
|||
{ |
|||
this.icon = icon; |
|||
this.text = text; |
|||
} |
|||
|
|||
public readonly IconData icon; |
|||
public readonly string text; |
|||
|
|||
public static readonly List<_Page> _allPages = new List<_Page> |
|||
{ |
|||
new _Page(icon: Icons.grade, text: "TRIUMPH"), |
|||
new _Page(icon: Icons.playlist_add, text: "NOTE"), |
|||
new _Page(icon: Icons.check_circle, text: "SUCCESS"), |
|||
new _Page(icon: Icons.question_answer, text: "OVERSTATE"), |
|||
new _Page(icon: Icons.sentiment_very_satisfied, text: "SATISFACTION"), |
|||
new _Page(icon: Icons.camera, text: "APERTURE"), |
|||
new _Page(icon: Icons.assignment_late, text: "WE MUST"), |
|||
new _Page(icon: Icons.assignment_turned_in, text: "WE CAN"), |
|||
new _Page(icon: Icons.group, text: "ALL"), |
|||
new _Page(icon: Icons.block, text: "EXCEPT"), |
|||
new _Page(icon: Icons.sentiment_very_dissatisfied, text: "CRYING"), |
|||
new _Page(icon: Icons.error, text: "MISTAKE"), |
|||
new _Page(icon: Icons.loop, text: "TRYING"), |
|||
new _Page(icon: Icons.cake, text: "CAKE") |
|||
}; |
|||
} |
|||
|
|||
|
|||
internal class ScrollableTabsDemo : StatefulWidget |
|||
{ |
|||
public static readonly string routeName = "/material/scrollable-tabs"; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new ScrollableTabsDemoState(); |
|||
} |
|||
} |
|||
|
|||
internal class ScrollableTabsDemoState : SingleTickerProviderStateMixin<ScrollableTabsDemo> |
|||
{ |
|||
private TabController _controller; |
|||
private TabsDemoStyle _demoStyle = TabsDemoStyle.iconsAndText; |
|||
private bool _customIndicator = false; |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
_controller = new TabController(vsync: this, length: _Page._allPages.Count); |
|||
} |
|||
|
|||
public override void dispose() |
|||
{ |
|||
_controller.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
private void changeDemoStyle(TabsDemoStyle style) |
|||
{ |
|||
setState(() => { _demoStyle = style; }); |
|||
} |
|||
|
|||
private Decoration getIndicator() |
|||
{ |
|||
if (!_customIndicator) |
|||
return new UnderlineTabIndicator(); |
|||
|
|||
switch (_demoStyle) |
|||
{ |
|||
case TabsDemoStyle.iconsAndText: |
|||
return new ShapeDecoration( |
|||
shape: new RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.all(Radius.circular(4.0f)), |
|||
side: new BorderSide( |
|||
color: Colors.white24, |
|||
width: 2.0f |
|||
) |
|||
) + new RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.all(Radius.circular(4.0f)), |
|||
side: new BorderSide( |
|||
color: Colors.transparent, |
|||
width: 4.0f |
|||
) |
|||
) |
|||
); |
|||
|
|||
case TabsDemoStyle.iconsOnly: |
|||
return new ShapeDecoration( |
|||
shape: new CircleBorder( |
|||
side: new BorderSide( |
|||
color: Colors.white24, |
|||
width: 4.0f |
|||
) |
|||
) + new CircleBorder( |
|||
side: new BorderSide( |
|||
color: Colors.transparent, |
|||
width: 4.0f |
|||
) |
|||
) |
|||
); |
|||
|
|||
case TabsDemoStyle.textOnly: |
|||
return new ShapeDecoration( |
|||
shape: new StadiumBorder( |
|||
side: new BorderSide( |
|||
color: Colors.white24, |
|||
width: 2.0f |
|||
) |
|||
) + new StadiumBorder( |
|||
side: new BorderSide( |
|||
color: Colors.transparent, |
|||
width: 4.0f |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
Color iconColor = Theme.of(context).accentColor; |
|||
return new Scaffold( |
|||
appBar: new AppBar( |
|||
title: new Text("Scrollable tabs"), |
|||
actions: new List<Widget> |
|||
{ |
|||
new MaterialDemoDocumentationButton(ScrollableTabsDemo.routeName), |
|||
new IconButton( |
|||
icon: new Icon(Icons.sentiment_very_satisfied), |
|||
onPressed: () => { setState(() => { _customIndicator = !_customIndicator; }); } |
|||
), |
|||
new PopupMenuButton<TabsDemoStyle>( |
|||
onSelected: changeDemoStyle, |
|||
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<TabsDemoStyle>> |
|||
{ |
|||
new PopupMenuItem<TabsDemoStyle>( |
|||
value: TabsDemoStyle.iconsAndText, |
|||
child: new Text("Icons and text") |
|||
), |
|||
new PopupMenuItem<TabsDemoStyle>( |
|||
value: TabsDemoStyle.iconsOnly, |
|||
child: new Text("Icons only") |
|||
), |
|||
new PopupMenuItem<TabsDemoStyle>( |
|||
value: TabsDemoStyle.textOnly, |
|||
child: new Text("Text only") |
|||
) |
|||
} |
|||
) |
|||
}, |
|||
bottom: new TabBar( |
|||
controller: _controller, |
|||
isScrollable: true, |
|||
indicator: getIndicator(), |
|||
tabs: _Page._allPages.Select<_Page, Widget>((_Page page) => |
|||
{ |
|||
D.assert(_demoStyle != null); |
|||
switch (_demoStyle) |
|||
{ |
|||
case TabsDemoStyle.iconsAndText: |
|||
return new Tab(text: page.text, icon: new Icon(page.icon)); |
|||
case TabsDemoStyle.iconsOnly: |
|||
return new Tab(icon: new Icon(page.icon)); |
|||
case TabsDemoStyle.textOnly: |
|||
return new Tab(text: page.text); |
|||
} |
|||
|
|||
return null; |
|||
}).ToList() |
|||
) |
|||
), |
|||
body: new TabBarView( |
|||
controller: _controller, |
|||
children: _Page._allPages.Select<_Page, Widget>((_Page page) => |
|||
{ |
|||
return new SafeArea( |
|||
top: false, |
|||
bottom: false, |
|||
child: new Container( |
|||
key: new ObjectKey(page.icon), |
|||
padding: EdgeInsets.all(12.0f), |
|||
child: new Card( |
|||
child: new Center( |
|||
child: new Icon( |
|||
page.icon, |
|||
color: iconColor, |
|||
size: 128.0f |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
}).ToList() |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using UIWidgetsGallery.gallery; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.demo.material |
|||
{ |
|||
internal static class SelectionControlDemoUtils |
|||
{ |
|||
public static readonly string _checkboxText = |
|||
"Checkboxes allow the user to select multiple options from a set. " + |
|||
"A normal checkbox\"s value is true or false and a tristate checkbox\"s " + |
|||
"value can also be null."; |
|||
|
|||
public static readonly string _checkboxCode = "selectioncontrols_checkbox"; |
|||
|
|||
public static readonly string _radioText = |
|||
"Radio buttons allow the user to select one option from a set. Use radio " + |
|||
"buttons for exclusive selection if you think that the user needs to see " + |
|||
"all available options side-by-side."; |
|||
|
|||
public static readonly string _radioCode = "selectioncontrols_radio"; |
|||
|
|||
public static readonly string _switchText = |
|||
"On/off switches toggle the state of a single settings option. The option " + |
|||
"that the switch controls, as well as the state it’s in, should be made " + |
|||
"clear from the corresponding inline label."; |
|||
|
|||
public static readonly string _switchCode = "selectioncontrols_switch"; |
|||
} |
|||
|
|||
internal class SelectionControlsDemo : StatefulWidget |
|||
{ |
|||
public static readonly string routeName = "/material/selection-controls"; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _SelectionControlsDemoState(); |
|||
} |
|||
} |
|||
|
|||
internal class _SelectionControlsDemoState : State<SelectionControlsDemo> |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
List<ComponentDemoTabData> demos = new List<ComponentDemoTabData> |
|||
{ |
|||
new ComponentDemoTabData( |
|||
tabName: "CHECKBOX", |
|||
description: SelectionControlDemoUtils._checkboxText, |
|||
demoWidget: buildCheckbox(), |
|||
exampleCodeTag: SelectionControlDemoUtils._checkboxCode, |
|||
documentationUrl: "https://docs.flutter.io/flutter/material/Checkbox-class.html" |
|||
), |
|||
new ComponentDemoTabData( |
|||
tabName: "RADIO", |
|||
description: SelectionControlDemoUtils._radioText, |
|||
demoWidget: buildRadio(), |
|||
exampleCodeTag: SelectionControlDemoUtils._radioCode, |
|||
documentationUrl: "https://docs.flutter.io/flutter/material/Radio-class.html" |
|||
), |
|||
new ComponentDemoTabData( |
|||
tabName: "SWITCH", |
|||
description: SelectionControlDemoUtils._switchText, |
|||
demoWidget: buildSwitch(), |
|||
exampleCodeTag: SelectionControlDemoUtils._switchCode, |
|||
documentationUrl: "https://docs.flutter.io/flutter/material/Switch-class.html" |
|||
) |
|||
}; |
|||
|
|||
return new TabbedComponentDemoScaffold( |
|||
title: "Selection controls", |
|||
demos: demos |
|||
); |
|||
} |
|||
|
|||
private bool checkboxValueA = true; |
|||
private bool checkboxValueB = false; |
|||
private bool checkboxValueC; |
|||
private int radioValue = 0; |
|||
private bool switchValue = false; |
|||
|
|||
private void handleRadioValueChanged(int value) |
|||
{ |
|||
setState(() => { radioValue = value; }); |
|||
} |
|||
|
|||
private Widget buildCheckbox() |
|||
{ |
|||
return new Align( |
|||
alignment: new Alignment(0.0f, -0.2f), |
|||
child: new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
new Checkbox( |
|||
value: checkboxValueA, |
|||
onChanged: (bool? value) => { setState(() => { checkboxValueA = value.Value; }); } |
|||
), |
|||
new Checkbox( |
|||
value: checkboxValueB, |
|||
onChanged: (bool? value) => { setState(() => { checkboxValueB = value.Value; }); } |
|||
), |
|||
new Checkbox( |
|||
value: checkboxValueC, |
|||
tristate: true, |
|||
onChanged: (bool? value) => { setState(() => { checkboxValueC = value.Value; }); } |
|||
) |
|||
} |
|||
), |
|||
new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
// Disabled checkboxes
|
|||
new Checkbox(value: true, onChanged: null), |
|||
new Checkbox(value: false, onChanged: null), |
|||
new Checkbox(value: null, tristate: true, onChanged: null), |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
|
|||
private Widget buildRadio() |
|||
{ |
|||
return new Align( |
|||
alignment: new Alignment(0.0f, -0.2f), |
|||
child: new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
new Radio<int>( |
|||
value: 0, |
|||
groupValue: radioValue, |
|||
onChanged: handleRadioValueChanged |
|||
), |
|||
new Radio<int>( |
|||
value: 1, |
|||
groupValue: radioValue, |
|||
onChanged: handleRadioValueChanged |
|||
), |
|||
new Radio<int>( |
|||
value: 2, |
|||
groupValue: radioValue, |
|||
onChanged: handleRadioValueChanged |
|||
) |
|||
} |
|||
), |
|||
// Disabled radio buttons
|
|||
new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
new Radio<int>( |
|||
value: 0, |
|||
groupValue: 0, |
|||
onChanged: null |
|||
), |
|||
new Radio<int>( |
|||
value: 1, |
|||
groupValue: 0, |
|||
onChanged: null |
|||
), |
|||
new Radio<int>( |
|||
value: 2, |
|||
groupValue: 0, |
|||
onChanged: null |
|||
) |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
|
|||
private Widget buildSwitch() |
|||
{ |
|||
return new Align( |
|||
alignment: new Alignment(0.0f, -0.2f), |
|||
child: new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> |
|||
{ |
|||
Switch.adaptive( |
|||
value: switchValue, |
|||
onChanged: (bool? value) => { setState(() => { switchValue = value.Value; }); } |
|||
), |
|||
// Disabled switches
|
|||
Switch.adaptive(value: true, onChanged: null), |
|||
Switch.adaptive(value: false, onChanged: null) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue