浏览代码

add sample and bug fixes

/siyaoH-1.17-PlatformMessage
xingwei.zhu 4 年前
当前提交
556ac34b
共有 9 个文件被更改,包括 850 次插入210 次删除
  1. 425
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/menu_demo.cs
  2. 36
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs
  3. 19
      com.unity.uiwidgets/Runtime/animation/animation_controller.cs
  4. 5
      com.unity.uiwidgets/Runtime/material/checkbox_list_tile.cs
  5. 2
      com.unity.uiwidgets/Runtime/material/refresh_indicator.cs
  6. 97
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/overscroll_demo.cs
  7. 105
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/page_selector_demo.cs
  8. 140
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/progress_indicator_demo.cs
  9. 231
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/reorderable_list_demo.cs

425
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/menu_demo.cs


using System;
using System.Collections.Generic;
using uiwidgets;
using UIWidgetsGallery.gallery;

namespace UIWidgetsGallery.demo.material
{
class MenuDemo : StatefulWidget {
internal class MenuDemo : StatefulWidget
{
public static readonly string routeName = "/material/menu";
public static readonly string routeName = "/material/menu";
public override State createState() => new MenuDemoState();
}
class MenuDemoState : State<MenuDemo> {
readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
public override State createState()
{
return new MenuDemoState();
}
}
static readonly string _simpleValue1 = "Menu item value one";
static readonly string _simpleValue2 = "Menu item value two";
static readonly string _simpleValue3 = "Menu item value three";
string _simpleValue;
internal class MenuDemoState : State<MenuDemo>
{
private readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
readonly string _checkedValue1 = "One";
readonly string _checkedValue2 = "Two";
readonly string _checkedValue3 = "Free";
readonly string _checkedValue4 = "Four";
List<string> _checkedValues;
private static readonly string _simpleValue1 = "Menu item value one";
private static readonly string _simpleValue2 = "Menu item value two";
private static readonly string _simpleValue3 = "Menu item value three";
private string _simpleValue;
public override void initState() {
base.initState();
_simpleValue = _simpleValue2;
_checkedValues = new List<string>{_checkedValue3};
}
private readonly string _checkedValue1 = "One";
private readonly string _checkedValue2 = "Two";
private readonly string _checkedValue3 = "Free";
private readonly string _checkedValue4 = "Four";
private List<string> _checkedValues;
void showInSnackBar(string value) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text(value)
));
}
public override void initState()
{
base.initState();
_simpleValue = _simpleValue2;
_checkedValues = new List<string> {_checkedValue3};
}
List<string> _showSelection = new List<string> { _simpleValue1, _simpleValue2, _simpleValue3 };
private void showInSnackBar(string value)
{
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text(value)
));
}
void showMenuSelection(string value) {
if (_showSelection.Contains(value))
_simpleValue = value;
showInSnackBar($"You selected: {value}");
}
private List<string> _showSelection = new List<string> {_simpleValue1, _simpleValue2, _simpleValue3};
void showCheckedMenuSelections(String value) {
if (_checkedValues.Contains(value))
_checkedValues.Remove(value);
else
_checkedValues.Add(value);
private void showMenuSelection(string value)
{
if (_showSelection.Contains(value))
_simpleValue = value;
showInSnackBar($"You selected: {value}");
}
showInSnackBar($"Checked {_checkedValues.Count} items");
}
private void showCheckedMenuSelections(string value)
{
if (_checkedValues.Contains(value))
_checkedValues.Remove(value);
else
_checkedValues.Add(value);
bool isChecked(string value) => _checkedValues.Contains(value);
showInSnackBar($"Checked {_checkedValues.Count} items");
}
public override Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("Menus"),
actions: new List<Widget>{
new MaterialDemoDocumentationButton(MenuDemo.routeName),
new PopupMenuButton<string>(
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>{
new PopupMenuItem<string>(
value: "Toolbar menu",
child: new Text("Toolbar menu")
),
new PopupMenuItem<string>(
value: "Right here",
child: new Text("Right here")
),
new PopupMenuItem<string>(
value: "Hooray!",
child: new Text("Hooray!")
)
}
)
private bool isChecked(string value)
{
return _checkedValues.Contains(value);
),
body: new ListTileTheme(
iconColor: Theme.of(context).brightness == Brightness.light
? Colors.grey[600]
: Colors.grey[500],
child: new ListView(
padding: material_.kMaterialListPadding,
children: new List<Widget>{
// Pressing the PopupMenuButton on the right of this item shows
// a simple menu with one disabled item. Typically the contents
// of this "contextual menu" would reflect the app's state.
new ListTile(
title: new Text("An item with a context menu button"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>{
new PopupMenuItem<string>(
value: _simpleValue1,
child: new Text("Context menu item one")
),
new PopupMenuItem<string>(
enabled: false,
child: new Text("A disabled menu item")
),
new PopupMenuItem<string>(
value: _simpleValue3,
child: new Text("Context menu item three")
)
}
)
),
// Pressing the PopupMenuButton on the right of this item shows
// a menu whose items have text labels and icons and a divider
// That separates the first three items from the last one.
new ListTile(
title: new Text("An item with a sectioned menu"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>{
new PopupMenuItem<string>(
value: "Preview",
child: new ListTile(
leading: new Icon(Icons.visibility),
title: new Text("Preview")
)
),
new PopupMenuItem<string>(
value: "Share",
child: new ListTile(
leading: new Icon(Icons.person_add),
title: new Text("Share")
)
),
new PopupMenuItem<string>(
value: "Get Link",
child: new ListTile(
leading: new Icon(Icons.link),
title: new Text("Get link")
)
),
new PopupMenuDivider<string>(),
new PopupMenuItem<string>(
value: "Remove",
child: new ListTile(
leading: new Icon(Icons.delete),
title: new Text("Remove")
public override Widget build(BuildContext context)
{
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("Menus"),
actions: new List<Widget>
{
new MaterialDemoDocumentationButton(MenuDemo.routeName),
new PopupMenuButton<string>(
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>
{
new PopupMenuItem<string>(
value: "Toolbar menu",
child: new Text("Toolbar menu")
),
new PopupMenuItem<string>(
value: "Right here",
child: new Text("Right here")
),
new PopupMenuItem<string>(
value: "Hooray!",
child: new Text("Hooray!")
)
}
)
}
),
body: new ListTileTheme(
iconColor: Theme.of(context).brightness == Brightness.light
? Colors.grey[600]
: Colors.grey[500],
child: new ListView(
padding: material_.kMaterialListPadding,
children: new List<Widget>
{
// Pressing the PopupMenuButton on the right of this item shows
// a simple menu with one disabled item. Typically the contents
// of this "contextual menu" would reflect the app's state.
new ListTile(
title: new Text("An item with a context menu button"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>
{
new PopupMenuItem<string>(
value: _simpleValue1,
child: new Text("Context menu item one")
),
new PopupMenuItem<string>(
enabled: false,
child: new Text("A disabled menu item")
),
new PopupMenuItem<string>(
value: _simpleValue3,
child: new Text("Context menu item three")
)
}
)
),
// Pressing the PopupMenuButton on the right of this item shows
// a menu whose items have text labels and icons and a divider
// That separates the first three items from the last one.
new ListTile(
title: new Text("An item with a sectioned menu"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showMenuSelection,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>
{
new PopupMenuItem<string>(
value: "Preview",
child: new ListTile(
leading: new Icon(Icons.visibility),
title: new Text("Preview")
)
),
new PopupMenuItem<string>(
value: "Share",
child: new ListTile(
leading: new Icon(Icons.person_add),
title: new Text("Share")
)
),
new PopupMenuItem<string>(
value: "Get Link",
child: new ListTile(
leading: new Icon(Icons.link),
title: new Text("Get link")
)
),
new PopupMenuDivider<string>(),
new PopupMenuItem<string>(
value: "Remove",
child: new ListTile(
leading: new Icon(Icons.delete),
title: new Text("Remove")
)
)
}
)
),
// This entire list item is a PopupMenuButton. Tapping anywhere shows
// a menu whose current value is highlighted and aligned over the
// list item's center line.
new PopupMenuButton<string>(
padding: EdgeInsets.zero,
initialValue: _simpleValue,
onSelected: showMenuSelection,
child: new ListTile(
title: new Text("An item with a simple menu"),
subtitle: new Text(_simpleValue)
),
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>
{
new PopupMenuItem<string>(
value: _simpleValue1,
child: new Text(_simpleValue1)
),
new PopupMenuItem<string>(
value: _simpleValue2,
child: new Text(_simpleValue2)
),
new PopupMenuItem<string>(
value: _simpleValue3,
child: new Text(_simpleValue3)
)
}
),
// Pressing the PopupMenuButton on the right of this item shows a menu
// whose items have checked icons that reflect this app's state.
new ListTile(
title: new Text("An item with a checklist menu"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showCheckedMenuSelections,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>
{
new CheckedPopupMenuItem<string>(
value: _checkedValue1,
isChecked: isChecked(_checkedValue1),
child: new Text(_checkedValue1)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue2,
enabled: false,
isChecked: isChecked(_checkedValue2),
child: new Text(_checkedValue2)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue3,
isChecked: isChecked(_checkedValue3),
child: new Text(_checkedValue3)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue4,
isChecked: isChecked(_checkedValue4),
child: new Text(_checkedValue4)
)
}
)
)
}
)
}
)
),
// This entire list item is a PopupMenuButton. Tapping anywhere shows
// a menu whose current value is highlighted and aligned over the
// list item's center line.
new PopupMenuButton<string>(
padding: EdgeInsets.zero,
initialValue: _simpleValue,
onSelected: showMenuSelection,
child: new ListTile(
title: new Text("An item with a simple menu"),
subtitle: new Text(_simpleValue)
),
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>{
new PopupMenuItem<string>(
value: _simpleValue1,
child: new Text(_simpleValue1)
),
new PopupMenuItem<string>(
value: _simpleValue2,
child: new Text(_simpleValue2)
),
new PopupMenuItem<string>(
value: _simpleValue3,
child: new Text(_simpleValue3)
}
),
// Pressing the PopupMenuButton on the right of this item shows a menu
// whose items have checked icons that reflect this app's state.
new ListTile(
title: new Text("An item with a checklist menu"),
trailing: new PopupMenuButton<string>(
padding: EdgeInsets.zero,
onSelected: showCheckedMenuSelections,
itemBuilder: (BuildContext subContext) => new List<PopupMenuEntry<string>>{
new CheckedPopupMenuItem<string>(
value: _checkedValue1,
isChecked: isChecked(_checkedValue1),
child: new Text(_checkedValue1)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue2,
enabled: false,
isChecked: isChecked(_checkedValue2),
child: new Text(_checkedValue2)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue3,
isChecked: isChecked(_checkedValue3),
child: new Text(_checkedValue3)
),
new CheckedPopupMenuItem<string>(
value: _checkedValue4,
isChecked: isChecked(_checkedValue4),
child: new Text(_checkedValue4)
)
}
)
)
}
)
)
);
}
}
);
}
}
}

36
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs


buildRoute: (BuildContext context) => new DataTableDemo()
),
new GalleryDemo(
title: "Pull to refresh",
subtitle: "Refresh indicators",
icon: GalleryIcons.refresh,
category: GalleryDemoCategory._kMaterialComponents,
routeName: OverscrollDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/RefreshIndicator-class.html",
buildRoute: (BuildContext context) => new OverscrollDemo()
),
new GalleryDemo(
title: "Search",
subtitle: "Expandable search",
icon: Icons.search,

buildRoute: (BuildContext context) => new LeaveBehindDemo()
),
new GalleryDemo(
title: "Lists: reorderable",
subtitle: "Reorderable lists",
icon: GalleryIcons.list_alt,
category: GalleryDemoCategory._kMaterialComponents,
routeName: ReorderableListDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/ReorderableListView-class.html",
buildRoute: (BuildContext context) => new ReorderableListDemo()
),
new GalleryDemo(
title: "Menus",
subtitle: "Menu buttons and simple menus",
icon: GalleryIcons.more_vert,

buildRoute: (BuildContext context) => new MenuDemo()
),
new GalleryDemo(
title: "Pagination",
subtitle: "PageView with indicator",
icon: GalleryIcons.page_control,
category: GalleryDemoCategory._kMaterialComponents,
routeName: PageSelectorDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/TabBarView-class.html",
buildRoute: (BuildContext context) => new PageSelectorDemo()
),
new GalleryDemo(
title: "Progress indicators",
subtitle: "Linear, circular, indeterminate",
icon: GalleryIcons.progress_activity,
category: GalleryDemoCategory._kMaterialComponents,
routeName: ProgressIndicatorDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/LinearProgressIndicator-class.html",
buildRoute: (BuildContext context) => new ProgressIndicatorDemo()
)
};

19
com.unity.uiwidgets/Runtime/animation/animation_controller.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.physics;
using Unity.UIWidgets.scheduler2;
using UnityEngine;
using Ticker = Unity.UIWidgets.scheduler2.Ticker;
using TickerFuture = Unity.UIWidgets.scheduler2.TickerFuture;
using TickerProvider = Unity.UIWidgets.scheduler2.TickerProvider;

reverse,
}
public enum AnimationBehavior {
normal,
preserve,
}
public class AnimationController :
AnimationLocalStatusListenersMixinAnimationLocalListenersMixinAnimationEagerListenerMixinAnimation<float> {
public AnimationController(

string debugLabel = null,
float lowerBound = 0.0f,
float upperBound = 1.0f,
AnimationBehavior animationBehavior = AnimationBehavior.normal,
TickerProvider vsync = null
) {
D.assert(upperBound >= lowerBound);

this.debugLabel = debugLabel;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.animationBehavior = animationBehavior;
_ticker = vsync.createTicker(_tick);
_internalSetValue(value ?? lowerBound);

TimeSpan? duration = null,
TimeSpan? reverseDuration = null,
string debugLabel = null,
AnimationBehavior? animationBehavior = null,
D.assert(animationBehavior != null);
lowerBound = float.NegativeInfinity;
upperBound = float.PositiveInfinity;
_direction = _AnimationDirection.forward;

this.debugLabel = debugLabel;
this.animationBehavior = animationBehavior.Value;
_ticker = vsync.createTicker(_tick);
_internalSetValue(value);

TimeSpan? duration = null,
TimeSpan? reverseDuration = null,
string debugLabel = null,
TickerProvider vsync = null
TickerProvider vsync = null,
AnimationBehavior animationBehavior = AnimationBehavior.preserve
return new AnimationController(value, duration, reverseDuration, debugLabel, vsync);
return new AnimationController(value, duration, reverseDuration, debugLabel, animationBehavior, vsync);
public readonly AnimationBehavior animationBehavior;
public readonly string debugLabel;

5
com.unity.uiwidgets/Runtime/material/checkbox_list_tile.cs


namespace Unity.UIWidgets.material {
public class CheckboxListTile : StatelessWidget {
public CheckboxListTile(
Key key,
Key key = null,
bool? value = null,
ValueChanged<bool?> onChanged = null,
Color activeColor = null,

this.secondary = secondary;
this.selected = selected;
this.controlAffinity = controlAffinity;
this.value = value;
this.activeColor = activeColor;
this.onChanged = onChanged;
}
public readonly bool? value;

2
com.unity.uiwidgets/Runtime/material/refresh_indicator.cs


});
}
Future show(bool atTop = true) {
public Future show(bool atTop = true) {
if (_mode != _RefreshIndicatorMode.refresh && _mode != _RefreshIndicatorMode.snap) {
if (_mode == null) {
_start(atTop ? AxisDirection.down : AxisDirection.up);

97
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/overscroll_demo.cs


using System;
using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.demo.material
{
internal enum IndicatorType
{
overscroll,
refresh
}
internal class OverscrollDemo : StatefulWidget
{
public OverscrollDemo(Key key = null) : base(key: key)
{
}
public static readonly string routeName = "/material/overscroll";
public override State createState()
{
return new OverscrollDemoState();
}
}
internal class OverscrollDemoState : State<OverscrollDemo>
{
private readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
private readonly GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>.key();
private static readonly List<string> _items = new List<string>
{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
};
private Future _handleRefresh()
{
Completer completer = Completer.create();
Timer.create(new TimeSpan(0, 0, 0, 3), () => { completer.complete(); });
return completer.future.then((_) =>
{
_scaffoldKey.currentState?.showSnackBar(new SnackBar(
content: new Text("Refresh complete"),
action: new SnackBarAction(
label: "RETRY",
onPressed: () => { _refreshIndicatorKey.currentState.show(); }
)
));
});
}
public override Widget build(BuildContext context)
{
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("Pull to refresh"),
actions: new List<Widget>
{
new MaterialDemoDocumentationButton(OverscrollDemo.routeName),
new IconButton(
icon: new Icon(Icons.refresh),
tooltip: "Refresh",
onPressed: () => { _refreshIndicatorKey.currentState.show(); }
)
}
),
body: new RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _handleRefresh,
child: new Scrollbar(
child: ListView.builder(
padding: material_.kMaterialListPadding,
itemCount: _items.Count,
itemBuilder: (BuildContext subContext, int index) =>
{
string item = _items[index];
return new ListTile(
isThreeLine: true,
leading: new CircleAvatar(child: new Text(item)),
title: new Text($"This item represents {item}."),
subtitle: new Text(
"Even more additional list item information appears on line three.")
);
}
)
)
)
);
}
}
}

105
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/page_selector_demo.cs


using System.Collections.Generic;
using System.Linq;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.demo.material
{
class _PageSelector : StatelessWidget {
public _PageSelector(List<Icon> icons)
{
this.icons = icons;
}
public readonly List<Icon> icons;
void _handleArrowButtonPress(BuildContext context, int delta) {
TabController controller = DefaultTabController.of(context);
if (!controller.indexIsChanging)
controller.animateTo((controller.index + delta).clamp(0, icons.Count - 1));
}
public override Widget build(BuildContext context) {
TabController controller = DefaultTabController.of(context);
Color color = Theme.of(context).accentColor;
return new SafeArea(
top: false,
bottom: false,
child: new Column(
children: new List<Widget>{
new Container(
margin: EdgeInsets.only(top: 16.0f),
child: new Row(
children: new List<Widget>{
new IconButton(
icon: new Icon(Icons.chevron_left),
color: color,
onPressed: () => { _handleArrowButtonPress(context, -1); },
tooltip: "Page back"
),
new TabPageSelector(controller: controller),
new IconButton(
icon: new Icon(Icons.chevron_right),
color: color,
onPressed: () => { _handleArrowButtonPress(context, 1); },
tooltip: "Page forward"
)
},
mainAxisAlignment: MainAxisAlignment.spaceBetween
)
),
new Expanded(
child: new IconTheme(
data: new IconThemeData(
size: 128.0f,
color: color
),
child: new TabBarView(
children: icons.Select<Icon, Widget>((Icon icon) => {
return new Container(
padding: EdgeInsets.all(12.0f),
child: new Card(
child: new Center(
child: icon
)
)
);
}).ToList()
)
)
)
}
)
);
}
}
class PageSelectorDemo : StatelessWidget {
public static readonly string routeName = "/material/page-selector";
static readonly List<Icon> icons = new List<Icon>{
new Icon(Icons.event_icon),
new Icon(Icons.home),
new Icon(Icons.android),
new Icon(Icons.alarm),
new Icon(Icons.face),
new Icon(Icons.language)
};
public override Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Page selector"),
actions: new List<Widget>{new MaterialDemoDocumentationButton(routeName)}),
body: new DefaultTabController(
length: icons.Count,
child: new _PageSelector(icons: icons)
)
);
}
}
}

140
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/progress_indicator_demo.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.demo.material
{
class ProgressIndicatorDemo : StatefulWidget {
public static readonly string routeName = "/material/progress-indicator";
public override State createState() => new _ProgressIndicatorDemoState();
}
class _ProgressIndicatorDemoState : SingleTickerProviderStateMixin<ProgressIndicatorDemo> {
AnimationController _controller;
Animation<float> _animation;
public override void initState() {
base.initState();
_controller = new AnimationController(
duration: new TimeSpan(0, 0, 0, 0, 1500),
vsync: this,
animationBehavior: AnimationBehavior.preserve
);
_controller.forward();
_animation = new CurvedAnimation(
parent: _controller,
curve: new Interval(0.0f, 0.9f, curve: Curves.fastOutSlowIn),
reverseCurve: Curves.fastOutSlowIn
);
_animation.addStatusListener((AnimationStatus status) => {
if (status == AnimationStatus.dismissed)
_controller.forward();
else if (status == AnimationStatus.completed)
_controller.reverse();
});
}
public override void dispose() {
_controller.stop();
base.dispose();
}
void _handleTap() {
setState(() => {
// valueAnimation.isAnimating is part of our build state
if (_controller.isAnimating) {
_controller.stop();
} else {
switch (_controller.status) {
case AnimationStatus.dismissed:
case AnimationStatus.forward:
_controller.forward();
break;
case AnimationStatus.reverse:
case AnimationStatus.completed:
_controller.reverse();
break;
}
}
});
}
Widget _buildIndicators(BuildContext context, Widget child)
{
List<Widget> indicators = new List<Widget>
{
new SizedBox(
width: 200.0f,
child: new LinearProgressIndicator()
),
new LinearProgressIndicator(),
new LinearProgressIndicator(),
new LinearProgressIndicator(value: _animation.value),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: new List<Widget>
{
new CircularProgressIndicator(),
new SizedBox(
width: 20.0f,
height: 20.0f,
child: new CircularProgressIndicator(value: _animation.value)
),
new SizedBox(
width: 100.0f,
height: 20.0f,
child: new Text($"{(_animation.value * 100.0):F1}%",
textAlign: TextAlign.right
)
)
}
)
};
return new Column(
children: indicators
.Select<Widget, Widget>((Widget c) => new Container(child: c, margin: EdgeInsets.symmetric(vertical: 15.0f, horizontal: 20.0f)))
.ToList()
);
}
public override Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Progress indicators"),
actions: new List<Widget>{new MaterialDemoDocumentationButton(ProgressIndicatorDemo.routeName)}
),
body: new Center(
child: new SingleChildScrollView(
child: new DefaultTextStyle(
style: Theme.of(context).textTheme.headline6,
child: new GestureDetector(
onTap: _handleTap,
behavior: HitTestBehavior.opaque,
child: new SafeArea(
top: false,
bottom: false,
child: new Container(
padding: EdgeInsets.symmetric(vertical: 12.0f, horizontal: 8.0f),
child: new AnimatedBuilder(
animation: _animation,
builder: _buildIndicators
)
)
)
)
)
)
)
);
}
}
}

231
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/reorderable_list_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;
using UnityEngine;
namespace UIWidgetsGallery.demo.material
{
enum _ReorderableListType {
/// A list tile that contains a [CircleAvatar].
horizontalAvatar,
/// A list tile that contains a [CircleAvatar].
verticalAvatar,
/// A list tile that contains three lines of text and a checkbox.
threeLine,
}
class ReorderableListDemo : StatefulWidget {
public ReorderableListDemo(Key key = null) : base(key: key)
{
}
public static readonly string routeName = "/material/reorderable-list";
public override State createState() => new _ReorderableListDemoState();
}
class _ListItem {
public _ListItem(string value, bool? checkState)
{
this.value = value;
this.checkState = checkState;
}
public readonly string value;
internal bool? checkState;
}
class _ReorderableListDemoState : State<ReorderableListDemo> {
static readonly GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>.key();
PersistentBottomSheetController<object> _bottomSheet;
_ReorderableListType _itemType = _ReorderableListType.threeLine;
bool _reverse = false;
bool _reverseSort = false;
static readonly List<_ListItem> _items = new List<string>{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
}.Select<string, _ListItem>((string item) => new _ListItem(item, false)).ToList();
void changeItemType(_ReorderableListType type) {
setState(() => {
_itemType = type;
});
// Rebuild the bottom sheet to reflect the selected list view.
_bottomSheet?.setState(() => {
// Trigger a rebuild.
});
// Close the bottom sheet to give the user a clear view of the list.
_bottomSheet?.close();
}
void changeReverse(bool? newValue) {
setState(() => {
_reverse = newValue.Value;
});
// Rebuild the bottom sheet to reflect the selected list view.
_bottomSheet?.setState(() => {
// Trigger a rebuild.
});
// Close the bottom sheet to give the user a clear view of the list.
_bottomSheet?.close();
}
void _showConfigurationSheet() {
setState(() => {
_bottomSheet = scaffoldKey.currentState.showBottomSheet((BuildContext bottomSheetContext) => {
return new DecoratedBox(
decoration: new BoxDecoration(
border: new Border(top: new BorderSide(color: Colors.black26))
),
child: new ListView(
shrinkWrap: true,
primary: false,
children: new List<Widget>{
new CheckboxListTile(
dense: true,
title: new Text("Reverse"),
value: _reverse,
onChanged: changeReverse
),
new RadioListTile<_ReorderableListType>(
dense: true,
title: new Text("Horizontal Avatars"),
value: _ReorderableListType.horizontalAvatar,
groupValue: _itemType,
onChanged: changeItemType
),
new RadioListTile<_ReorderableListType>(
dense: true,
title: new Text("Vertical Avatars"),
value: _ReorderableListType.verticalAvatar,
groupValue: _itemType,
onChanged: changeItemType
),
new RadioListTile<_ReorderableListType>(
dense: true,
title: new Text("Three-line"),
value: _ReorderableListType.threeLine,
groupValue: _itemType,
onChanged: changeItemType
)
}
)
);
});
// Garbage collect the bottom sheet when it closes.
_bottomSheet.closed.whenComplete(() => {
if (mounted) {
setState(() => {
_bottomSheet = null;
});
}
});
});
}
Widget buildListTile(_ListItem item) {
Widget secondary = new Text(
"Even more additional list item information appears on line three."
);
Widget listTile = null;
switch (_itemType) {
case _ReorderableListType.threeLine:
listTile = new CheckboxListTile(
key: Key.key(item.value),
isThreeLine: true,
value: item.checkState ?? false,
onChanged: (bool? newValue) => {
setState(() => {
item.checkState = newValue.Value;
});
},
title: new Text($"This item represents {item.value}."),
subtitle: secondary,
secondary: new Icon(Icons.drag_handle)
);
break;
case _ReorderableListType.horizontalAvatar:
case _ReorderableListType.verticalAvatar:
listTile = new Container(
key: Key.key(item.value),
height: 100.0f,
width: 100.0f,
child: new CircleAvatar(child: new Text(item.value),
backgroundColor: Colors.green
)
);
break;
}
return listTile;
}
void _onReorder(int oldIndex, int newIndex) {
setState(() => {
if (newIndex > oldIndex) {
newIndex -= 1;
}
_ListItem item = _items[oldIndex];
_items.RemoveAt(oldIndex);
_items.Insert(newIndex, item);
});
}
public override Widget build(BuildContext context) {
return new Scaffold(
key: scaffoldKey,
appBar: new AppBar(
title: new Text("Reorderable list"),
actions: new List<Widget>{
new MaterialDemoDocumentationButton(ReorderableListDemo.routeName),
new IconButton(
icon: new Icon(Icons.sort_by_alpha),
tooltip: "Sort",
onPressed: () => {
setState(() => {
_reverseSort = !_reverseSort;
_items.Sort((_ListItem a, _ListItem b) => _reverseSort ? b.value.CompareTo(a.value) : a.value.CompareTo(b.value));
});
}
),
new IconButton(
icon: new Icon(
Theme.of(context).platform == RuntimePlatform.IPhonePlayer
? Icons.more_horiz
: Icons.more_vert
),
tooltip: "Show menu",
onPressed: _bottomSheet == null ? _showConfigurationSheet : (VoidCallback)null
)
}
),
body: new Scrollbar(
child: new ReorderableListView(
header: _itemType != _ReorderableListType.threeLine
? new Padding(
padding: EdgeInsets.all(8.0f),
child: new Text("Header of the list", style: Theme.of(context).textTheme.headline5))
: null,
onReorder: _onReorder,
reverse: _reverse,
scrollDirection: _itemType == _ReorderableListType.horizontalAvatar ? Axis.horizontal : Axis.vertical,
padding: EdgeInsets.symmetric(vertical: 8.0f),
children: _items.Select<_ListItem, Widget>(buildListTile).ToList()
)
)
);
}
}
}
正在加载...
取消
保存