xingwei.zhu
4 年前
当前提交
556ac34b
共有 9 个文件被更改,包括 850 次插入 和 210 次删除
-
425Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/menu_demo.cs
-
36Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs
-
19com.unity.uiwidgets/Runtime/animation/animation_controller.cs
-
5com.unity.uiwidgets/Runtime/material/checkbox_list_tile.cs
-
2com.unity.uiwidgets/Runtime/material/refresh_indicator.cs
-
97Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/overscroll_demo.cs
-
105Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/page_selector_demo.cs
-
140Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/progress_indicator_demo.cs
-
231Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/reorderable_list_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.") |
|||
); |
|||
} |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
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) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
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 |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
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() |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue