浏览代码

add more material samples to gallery

/zgh-devtools
xingweizhu 4 年前
当前提交
2f12a88f
共有 8 个文件被更改,包括 838 次插入0 次删除
  1. 252
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/date_and_time_picker_demo.cs
  2. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/date_and_time_picker_demo.cs.meta
  3. 229
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/dialog_demo.cs
  4. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/dialog_demo.cs.meta
  5. 270
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/drawer_demo.cs
  6. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/drawer_demo.cs.meta
  7. 75
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/elevation_demo.cs
  8. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/elevation_demo.cs.meta

252
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/date_and_time_picker_demo.cs


using System;
using System.Collections.Generic;
using System.Linq;
using uiwidgets;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.demo.material
{
internal class _InputDropdown : StatelessWidget
{
public _InputDropdown(
Key key = null,
Widget child = null,
string labelText = null,
string valueText = null,
TextStyle valueStyle = null,
VoidCallback onPressed = null
) : base(key: key)
{
this.labelText = labelText;
this.valueStyle = valueStyle;
this.valueText = valueText;
this.onPressed = onPressed;
this.child = child;
}
public readonly string labelText;
public readonly string valueText;
public readonly TextStyle valueStyle;
public readonly VoidCallback onPressed;
public readonly Widget child;
public override Widget build(BuildContext context)
{
return new InkWell(
onTap: () => this.onPressed?.Invoke(),
child: new InputDecorator(
decoration: new InputDecoration(
labelText: this.labelText
),
baseStyle: this.valueStyle,
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: new List<Widget>
{
new Text(this.valueText, style: this.valueStyle),
new Icon(Icons.arrow_drop_down,
color: Theme.of(context).brightness == Brightness.light
? Colors.grey.shade700
: Colors.white70
)
}
)
)
);
}
}
internal class _DateTimePicker : StatelessWidget
{
public _DateTimePicker(
Key key = null,
string labelText = null,
DateTime? selectedDate = null,
TimeOfDay selectedTime = null,
ValueChanged<DateTime?> selectDate = null,
ValueChanged<TimeOfDay> selectTime = null
) : base(key: key)
{
this.labelText = labelText;
this.selectDate = selectDate;
this.selectedTime = selectedTime;
this.selectDate = selectDate;
this.selectTime = selectTime;
}
public readonly string labelText;
public readonly DateTime? selectedDate;
public readonly TimeOfDay selectedTime;
public readonly ValueChanged<DateTime?> selectDate;
public readonly ValueChanged<TimeOfDay> selectTime;
private Future _selectDate(BuildContext context)
{
material_.showDatePicker(
context: context,
initialDate: this.selectedDate.Value,
firstDate: new DateTime(2015, 8, 0),
lastDate: new DateTime(2101, 0, 0)
).then((object value) =>
{
var picked = (DateTime) value;
if (picked != null && picked != this.selectedDate) this.selectDate(picked);
});
return Future.value();
}
private Future _selectTime(BuildContext context)
{
TimePickerUtils.showTimePicker(
context: context,
initialTime: this.selectedTime
).then((object value) =>
{
var picked = (TimeOfDay) value;
if (picked != null && picked != this.selectedTime) this.selectTime(picked);
});
return Future.value();
}
public override Widget build(BuildContext context)
{
TextStyle valueStyle = Theme.of(context).textTheme.headline6;
return new Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: new List<Widget>
{
new Expanded(
flex: 4,
child: new _InputDropdown(
labelText: this.labelText,
valueText: this.selectedDate.Value.ToString("yyyyMMdd"),
valueStyle: valueStyle,
onPressed: () => { this._selectDate(context); }
)
),
new SizedBox(width: 12.0f),
new Expanded(
flex: 3,
child: new _InputDropdown(
valueText: this.selectedTime.format(context),
valueStyle: valueStyle,
onPressed: () => { this._selectTime(context); }
)
)
}
);
}
}
internal class DateAndTimePickerDemo : StatefulWidget
{
public static readonly string routeName = "/material/date-and-time-pickers";
public override State createState()
{
return new _DateAndTimePickerDemoState();
}
}
internal class _DateAndTimePickerDemoState : State<DateAndTimePickerDemo>
{
private DateTime _fromDate = DateTime.Now;
private TimeOfDay _fromTime = new TimeOfDay(hour: 7, minute: 28);
private DateTime _toDate = DateTime.Now;
private TimeOfDay _toTime = new TimeOfDay(hour: 7, minute: 28);
public readonly List<string> _allActivities = new List<string> {"hiking", "swimming", "boating", "fishing"};
private string _activity = "fishing";
public override Widget build(BuildContext context)
{
return new Scaffold(
appBar: new AppBar(
title: new Text("Date and time pickers"),
actions: new List<Widget> {new MaterialDemoDocumentationButton(DateAndTimePickerDemo.routeName)}
),
body: new DropdownButtonHideUnderline(
child: new SafeArea(
top: false,
bottom: false,
child: new ListView(
padding: EdgeInsets.all(16.0f),
children: new List<Widget>
{
new TextField(
enabled: true,
decoration: new InputDecoration(
labelText: "Event name",
border: new OutlineInputBorder()
),
style: Theme.of(context).textTheme.headline4
),
new TextField(
decoration: new InputDecoration(
labelText: "Location"
),
style: Theme.of(context).textTheme.headline4.copyWith(fontSize: 20.0f)
),
new _DateTimePicker(
labelText: "From",
selectedDate: this._fromDate,
selectedTime: this._fromTime,
selectDate: (DateTime? date) =>
{
this.setState(() => { this._fromDate = date.Value; });
},
selectTime: (TimeOfDay time) => { this.setState(() => { this._fromTime = time; }); }
),
new _DateTimePicker(
labelText: "To",
selectedDate: this._toDate,
selectedTime: this._toTime,
selectDate: (DateTime? date) =>
{
this.setState(() => { this._toDate = date.Value; });
},
selectTime: (TimeOfDay time) => { this.setState(() => { this._toTime = time; }); }
),
new SizedBox(height: 8.0f),
new InputDecorator(
decoration: new InputDecoration(
labelText: "Activity",
hintText: "Choose an activity",
contentPadding: EdgeInsets.zero
),
isEmpty: this._activity == null,
child: new DropdownButton<string>(
value: this._activity,
onChanged: (string newValue) =>
{
this.setState(() => { this._activity = newValue; });
},
items: this._allActivities.Select<string, DropdownMenuItem<string>>(
(string value) =>
{
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).ToList()
)
)
}
)
)
)
);
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/date_and_time_picker_demo.cs.meta


fileFormatVersion: 2
guid: acc0d8629d884dbd9670b0cb3bb3e6ec
timeCreated: 1612430045

229
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/dialog_demo.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.demo.material
{
enum DialogDemoAction {
cancel,
discard,
disagree,
agree,
}
public static class GalleryDialogDemoUtils
{
public static readonly string _alertWithoutTitleText = "Discard draft?";
public static readonly string _alertWithTitleText =
"Let Google help apps determine location. This means sending anonymous location " +
"data to Google, even when no apps are running.";
}
class DialogDemoItem : StatelessWidget {
public DialogDemoItem(Key key = null, IconData icon = null, Color color = null, string text = null, VoidCallback onPressed = null) : base(key: key)
{
this.icon = icon;
this.color = color;
this.text = text;
this.onPressed = onPressed;
}
public readonly IconData icon;
public readonly Color color;
public readonly string text;
public readonly VoidCallback onPressed;
public override Widget build(BuildContext context) {
return new SimpleDialogOption(
onPressed: onPressed,
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget>{
new Icon(icon, size: 36.0f, color: color),
new Padding(
padding: EdgeInsets.only(left: 16.0f),
child: new Text(text)
)
}
)
);
}
}
class DialogDemo : StatefulWidget {
public static readonly string routeName = "/material/dialog";
public override State createState() => new DialogDemoState();
}
class DialogDemoState : State<DialogDemo> {
readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
TimeOfDay _selectedTime;
void initState() {
base.initState();
DateTime now = DateTime.Now;
_selectedTime = new TimeOfDay(hour: now.Hour, minute: now.Minute);
}
void showDemoDialog<T>(BuildContext context = null, Widget child = null) {
material_.showDialog<T>(
context: context,
builder: (BuildContext subContext) => child
)
.then((object value) => { // The value passed to Navigator.pop() or null.
if (value != null) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text($"You selected: {value}")
));
}
});
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextStyle dialogTextStyle = theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color);
var children = new List<Widget>
{
new RaisedButton(
child: new Text("ALERT"),
onPressed: () => {
showDemoDialog<DialogDemoAction>(
context: context,
child: new AlertDialog(
content: new Text(
GalleryDialogDemoUtils._alertWithoutTitleText,
style: dialogTextStyle
),
actions: new List<Widget>{
new FlatButton(
child: new Text("CANCEL"),
onPressed: () => { Navigator.pop(context, DialogDemoAction.cancel); }
),
new FlatButton(
child: new Text("DISCARD"),
onPressed: () => { Navigator.pop(context, DialogDemoAction.discard); }
)
}
)
);
}
),
new RaisedButton(
child: new Text("ALERT WITH TITLE"),
onPressed: () => {
showDemoDialog<DialogDemoAction>(
context: context,
child: new AlertDialog(
title: new Text("Use location service?"),
content: new Text(
GalleryDialogDemoUtils._alertWithTitleText,
style: dialogTextStyle
),
actions: new List<Widget>{
new FlatButton(
child: new Text("DISAGREE"),
onPressed: () => { Navigator.pop(context, DialogDemoAction.disagree); }
),
new FlatButton(
child: new Text("AGREE"),
onPressed: () => { Navigator.pop(context, DialogDemoAction.agree); }
)
}
)
);
}
),
new RaisedButton(
child: new Text("SIMPLE"),
onPressed: () => {
showDemoDialog<String>(
context: context,
child: new SimpleDialog(
title: new Text("Set backup account"),
children: new List<Widget>{
new DialogDemoItem(
icon: Icons.account_circle,
color: theme.primaryColor,
text: "username@gmail.com",
onPressed: () => { Navigator.pop(context, "username@gmail.com"); }
),
new DialogDemoItem(
icon: Icons.account_circle,
color: theme.primaryColor,
text: "user02@gmail.com",
onPressed: () => { Navigator.pop(context, "user02@gmail.com"); }
),
new DialogDemoItem(
icon: Icons.add_circle,
text: "add account",
color: theme.disabledColor
)
}
)
);
}
),
new RaisedButton(
child: new Text("CONFIRMATION"),
onPressed: () => {
TimePickerUtils.showTimePicker(
context: context,
initialTime: _selectedTime
)
.then((object value) => {
var time = (TimeOfDay) value;
if (time != null && time != _selectedTime) {
_selectedTime = time;
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text($"You selected: {time.format(context)}")
));
}
});
}
),
new RaisedButton(
child: new Text("FULLSCREEN"),
onPressed: () => {
/*Navigator.push(context, new MaterialPageRoute<DismissDialogAction>(
builder: (BuildContext subContext) => new FullScreenDialogDemo(),
fullscreenDialog: true
));*/
D.assert(false, () => "TO DO >>>");
}
)
};
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("Dialogs"),
actions: new List<Widget>{new MaterialDemoDocumentationButton(DialogDemo.routeName)}
),
body: new ListView(
padding: EdgeInsets.symmetric(vertical: 24.0f, horizontal: 72.0f),
children: children.Select<Widget, Widget>((Widget button) => {
return new Container(
padding: EdgeInsets.symmetric(vertical: 8.0f),
child: button
);
})
.ToList()
)
);
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/dialog_demo.cs.meta


fileFormatVersion: 2
guid: 3a34da8b9c0b4f368340c96381e1fc8f
timeCreated: 1612431714

270
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/drawer_demo.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace UIWidgetsGallery.demo.material
{
public static class DrawerDemoUtils
{
public static readonly string _kAsset0 = "people/square/trevor.png";
public static readonly string _kAsset1 = "people/square/stella.png";
public static readonly string _kAsset2 = "people/square/sandra.png";
public static readonly string _kGalleryAssetsPackage = "flutter_gallery_assets";
}
internal class DrawerDemo : StatefulWidget
{
public static readonly string routeName = "/material/drawer";
public override State createState()
{
return new _DrawerDemoState();
}
}
internal class _DrawerDemoState : TickerProviderStateMixin<DrawerDemo>
{
private GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
private static readonly List<string> _drawerContents = new List<string>
{
"A", "B", "C", "D", "E",
};
private static readonly Animatable<Offset> _drawerDetailsTween = new Tween<Offset>(
begin: new Offset(0.0f, -1.0f),
end: Offset.zero
).chain(new CurveTween(
curve: Curves.fastOutSlowIn
));
private AnimationController _controller;
private Animation<float> _drawerContentsOpacity;
private Animation<Offset> _drawerDetailsPosition;
private bool _showDrawerContents = true;
public override void initState()
{
base.initState();
this._controller = new AnimationController(
vsync: this,
duration: new TimeSpan(0, 0, 0, 0, 200)
);
this._drawerContentsOpacity = new CurvedAnimation(
parent: new ReverseAnimation(this._controller),
curve: Curves.fastOutSlowIn
);
this._drawerDetailsPosition = this._controller.drive(_drawerDetailsTween);
}
public override void dispose()
{
this._controller.dispose();
base.dispose();
}
private IconData _backIcon()
{
switch (Theme.of(this.context).platform)
{
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
return Icons.arrow_back_ios;
default:
return Icons.arrow_back_ios;
}
}
private void _showNotImplementedMessage()
{
Navigator.pop<object>(this.context); // Dismiss the drawer.
this._scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text("The drawer\"s items don\"t do anything")
));
}
public override Widget build(BuildContext context)
{
return new Scaffold(
drawerDragStartBehavior: DragStartBehavior.down,
key: this._scaffoldKey,
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(this._backIcon()),
alignment: Alignment.centerLeft,
tooltip: "Back",
onPressed: () => { Navigator.pop<object>(context); }
),
title: new Text("Navigation drawer"),
actions: new List<Widget> {new MaterialDemoDocumentationButton(DrawerDemo.routeName)}
),
drawer: new Drawer(
child: new Column(
children: new List<Widget>
{
new UserAccountsDrawerHeader(
accountName: new Text("Trevor Widget"),
accountEmail: new Text("trevor.widget@example.com"),
currentAccountPicture: new CircleAvatar(
backgroundImage: new FileImage(
DrawerDemoUtils._kAsset0
)
),
otherAccountsPictures: new List<Widget>
{
new GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onTap: () => { this._onOtherAccountsTap(context); },
child: new CircleAvatar(
backgroundImage: new FileImage(
DrawerDemoUtils._kAsset1
)
)
),
new GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onTap: () => { this._onOtherAccountsTap(context); },
child: new CircleAvatar(
backgroundImage: new FileImage(
DrawerDemoUtils._kAsset2
)
)
)
},
margin: EdgeInsets.zero,
onDetailsPressed: () =>
{
this._showDrawerContents = !this._showDrawerContents;
if (this._showDrawerContents)
this._controller.reverse();
else
this._controller.forward();
}
),
MediaQuery.removePadding(
context: context,
// DrawerHeader consumes top MediaQuery padding.
removeTop: true,
child: new Expanded(
child: new ListView(
dragStartBehavior: DragStartBehavior.down,
padding: EdgeInsets.only(top: 8.0f),
children: new List<Widget>
{
new Stack(
children: new List<Widget>
{
// The initial contents of the drawer.
new FadeTransition(
opacity: this._drawerContentsOpacity,
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: _drawerContents.Select<string, Widget>(
(string id) =>
{
return new ListTile(
leading: new CircleAvatar(child: new Text(id)),
title: new Text($"Drawer item {id}"),
onTap: this._showNotImplementedMessage
);
}).ToList()
)
),
// The drawer"s "details" view.
new SlideTransition(
position: this._drawerDetailsPosition,
child: new FadeTransition(
opacity: new ReverseAnimation(this._drawerContentsOpacity),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: new List<Widget>
{
new ListTile(
leading: new Icon(Icons.add),
title: new Text("Add account"),
onTap: this._showNotImplementedMessage
),
new ListTile(
leading: new Icon(Icons.settings),
title: new Text("Manage accounts"),
onTap: this._showNotImplementedMessage
)
}
)
)
)
}
)
}
)
)
)
}
)
),
body: new Center(
child: new InkWell(
onTap: () => { this._scaffoldKey.currentState.openDrawer(); },
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>
{
new Container(
width: 100.0f,
height: 100.0f,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
image: new FileImage(
DrawerDemoUtils._kAsset0
)
)
)
),
new Padding(
padding: EdgeInsets.only(top: 8.0f),
child: new Text("Tap here to open the drawer",
style: Theme.of(context).textTheme.subtitle1
)
)
}
)
)
)
);
}
private void _onOtherAccountsTap(BuildContext context)
{
material_.showDialog<object>(
context: context,
builder: (BuildContext subContext) =>
{
return new AlertDialog(
title: new Text("Account switching not implemented."),
actions: new List<Widget>
{
new FlatButton(
child: new Text("OK"),
onPressed: () => { Navigator.pop<object>(context); }
)
}
);
}
);
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/drawer_demo.cs.meta


fileFormatVersion: 2
guid: 5e98522fbce04fcab4ad8ef3806064b7
timeCreated: 1612434348

75
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/elevation_demo.cs


using System.Collections.Generic;
using System.Linq;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.demo.material
{
internal class ElevationDemo : StatefulWidget
{
public static readonly string routeName = "/material/elevation";
public override State createState()
{
return new _ElevationDemoState();
}
}
internal class _ElevationDemoState : State<ElevationDemo>
{
private bool _showElevation = true;
private List<Widget> buildCards()
{
List<float> elevations = new List<float>
{
0.0f,
1.0f,
2.0f,
3.0f,
4.0f,
5.0f,
8.0f,
16.0f,
24.0f
};
return elevations.Select<float, Widget>((float elevation) =>
{
return new Center(
child: new Card(
margin: EdgeInsets.all(20.0f),
elevation: this._showElevation ? elevation : 0.0f,
child: new SizedBox(
height: 100.0f,
width: 100.0f,
child: new Center(
child: new Text($"{elevation:F0} pt")
)
)
)
);
}).ToList();
}
public override Widget build(BuildContext context)
{
return new Scaffold(
appBar: new AppBar(
title: new Text("Elevation"),
actions: new List<Widget>
{
new MaterialDemoDocumentationButton(ElevationDemo.routeName),
new IconButton(
icon: new Icon(Icons.sentiment_very_satisfied),
onPressed: () => { this.setState(() => this._showElevation = !this._showElevation); }
)
}
),
body: new Scrollbar(child: new ListView(children: this.buildCards()))
);
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/elevation_demo.cs.meta


fileFormatVersion: 2
guid: d0ae191adfae42419c05afd3384d2d81
timeCreated: 1612433659
正在加载...
取消
保存