浏览代码

[Cupertino] Add Picker Demo to Gallery

/main
iizzaya 5 年前
当前提交
e23b8fac
共有 3 个文件被更改,包括 302 次插入8 次删除
  1. 16
      Samples/UIWidgetsGallery/gallery/demos.cs
  2. 283
      Samples/UIWidgetsGallery/demo/cupertino/cupertino_picker_demo.cs
  3. 11
      Samples/UIWidgetsGallery/demo/cupertino/cupertino_picker_demo.cs.meta

16
Samples/UIWidgetsGallery/gallery/demos.cs


documentationUrl: "https://docs.flutter.io/flutter/cupertino/CupertinoTabScaffold-class.html",
buildRoute: (BuildContext context) => new CupertinoNavigationDemo()
),
// new GalleryDemo(
// title: "Pickers",
// icon: GalleryIcons.@event,
// category: GalleryDemoCategory._kCupertinoComponents,
// routeName: CupertinoPickerDemo.routeName,
// documentationUrl: "https://docs.flutter.io/flutter/cupertino/CupertinoPicker-class.html",
// buildRoute: (BuildContext context) => CupertinoPickerDemo()
// ),
new GalleryDemo(
title: "Pickers",
icon: GalleryIcons.@event,
category: _kCupertinoComponents,
routeName: CupertinoPickerDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/cupertino/CupertinoPicker-class.html",
buildRoute: (BuildContext context) => new CupertinoPickerDemo()
),
// new GalleryDemo(
// title: "Pull to refresh",
// icon: GalleryIcons.cupertino_pull_to_refresh,

283
Samples/UIWidgetsGallery/demo/cupertino/cupertino_picker_demo.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class CupertinoPickerDemoUtils {
public const float _kPickerSheetHeight = 216.0f;
public const float _kPickerItemHeight = 32.0f;
}
class CupertinoPickerDemo : StatefulWidget {
public const string routeName = "/cupertino/picker";
public override State createState() {
return new _CupertinoPickerDemoState();
}
}
class _CupertinoPickerDemoState : State<CupertinoPickerDemo> {
int _selectedColorIndex = 0;
TimeSpan timer = new TimeSpan();
// Value that is shown in the date picker in date mode.
DateTime date = DateTime.Now;
// Value that is shown in the date picker in time mode.
DateTime time = DateTime.Now;
// Value that is shown in the date picker in dateAndTime mode.
DateTime dateTime = DateTime.Now;
Widget _buildMenu(List<Widget> children) {
return new Container(
decoration: new BoxDecoration(
color: CupertinoTheme.of(this.context).scaffoldBackgroundColor,
border: new Border(
top: new BorderSide(color: new Color(0xFFBCBBC1), width: 0.0f),
bottom: new BorderSide(color: new Color(0xFFBCBBC1), width: 0.0f)
)
),
height: 44.0f,
child: new Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0f),
child: new SafeArea(
top: false,
bottom: false,
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: children
)
)
)
);
}
Widget _buildBottomPicker(Widget picker) {
return new Container(
height: CupertinoPickerDemoUtils._kPickerSheetHeight,
padding: EdgeInsets.only(top: 6.0f),
color: CupertinoColors.white,
child: new DefaultTextStyle(
style: new TextStyle(
color: CupertinoColors.black,
fontSize: 22.0f
),
child: new GestureDetector(
// Blocks taps from propagating to the modal sheet and popping.
onTap: () => { },
child: new SafeArea(
top: false,
child: picker
)
)
)
);
}
Widget _buildColorPicker(BuildContext context) {
FixedExtentScrollController scrollController =
new FixedExtentScrollController(initialItem: this._selectedColorIndex);
List<Widget> generateList() {
var list = new List<Widget>();
foreach (var item in CupertinoNavigationDemoUtils.coolColorNames) {
list.Add(new Center(child:
new Text(item)
));
}
return list;
}
return new GestureDetector(
onTap: () => {
CupertinoRouteUtils.showCupertinoModalPopup(
context: context,
builder: (BuildContext _context) => {
return this._buildBottomPicker(
new CupertinoPicker(
scrollController: scrollController,
itemExtent: CupertinoPickerDemoUtils._kPickerItemHeight,
backgroundColor: CupertinoColors.white,
onSelectedItemChanged: (int index) => {
this.setState(() => this._selectedColorIndex = index);
},
children: generateList()
)
);
}
);
},
child: this._buildMenu(new List<Widget> {
new Text("Favorite Color"),
new Text(
CupertinoNavigationDemoUtils.coolColorNames[this._selectedColorIndex],
style: new TextStyle(
color: CupertinoColors.inactiveGray
)
)
}
)
);
}
Widget _buildCountdownTimerPicker(BuildContext context) {
return new GestureDetector(
onTap: () => {
CupertinoRouteUtils.showCupertinoModalPopup(
context: context,
builder: (BuildContext _context) => {
return this._buildBottomPicker(
new CupertinoTimerPicker(
initialTimerDuration: this.timer,
onTimerDurationChanged: (TimeSpan newTimer) => {
this.setState(() => this.timer = newTimer);
}
)
);
}
);
},
child: this._buildMenu(new List<Widget> {
new Text("Countdown Timer"),
new Text(
$"{this.timer.Hours}:" +
$"{(this.timer.Minutes % 60).ToString("00")}:" +
$"{(this.timer.Seconds % 60).ToString("00")}",
style: new TextStyle(color: CupertinoColors.inactiveGray)
)
}
)
);
}
Widget _buildDatePicker(BuildContext context) {
return new GestureDetector(
onTap: () => {
CupertinoRouteUtils.showCupertinoModalPopup(
context: context,
builder: (BuildContext _context) => {
return this._buildBottomPicker(
new CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: this.date,
onDateTimeChanged: (DateTime newDateTime) => {
this.setState(() => this.date = newDateTime);
}
)
);
}
);
},
child: this._buildMenu(new List<Widget> {
new Text("Date"),
new Text(
this.date.ToString("MMMM dd, yyyy"),
style: new TextStyle(color: CupertinoColors.inactiveGray)
)
}
)
);
}
Widget _buildTimePicker(BuildContext context) {
return new GestureDetector(
onTap: () => {
CupertinoRouteUtils.showCupertinoModalPopup(
context: context,
builder: (BuildContext _context) => {
return this._buildBottomPicker(
new CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
initialDateTime: this.time,
onDateTimeChanged: (DateTime newDateTime) => {
this.setState(() => this.time = newDateTime);
}
)
);
}
);
},
child: this._buildMenu(new List<Widget> {
new Text("Time"),
new Text(
this.time.ToString("h:mm tt"),
style: new TextStyle(color: CupertinoColors.inactiveGray)
)
}
)
);
}
Widget _buildDateAndTimePicker(BuildContext context) {
return new GestureDetector(
onTap: () => {
CupertinoRouteUtils.showCupertinoModalPopup(
context: context,
builder: (BuildContext _context) => {
return this._buildBottomPicker(
new CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
initialDateTime: this.dateTime,
onDateTimeChanged: (DateTime newDateTime) => {
this.setState(() => this.dateTime = newDateTime);
}
)
);
}
);
},
child: this._buildMenu(new List<Widget> {
new Text("Date and Time"),
new Text(
this.dateTime.ToString("MMMM dd, yyyy h:mm tt"),
style: new TextStyle(color: CupertinoColors.inactiveGray)
)
}
)
);
}
public override Widget build(BuildContext context) {
return new CupertinoPageScaffold(
navigationBar: new CupertinoNavigationBar(
middle: new Text("Picker"),
// We"re specifying a back label here because the previous page is a
// Material page. CupertinoPageRoutes could auto-populate these back
// labels.
previousPageTitle: "Cupertino",
trailing: new CupertinoDemoDocumentationButton(CupertinoPickerDemo.routeName)
),
child: new DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: new DecoratedBox(
decoration: new BoxDecoration(
color: CupertinoTheme.of(context).brightness == Brightness.light
? CupertinoColors.extraLightBackgroundGray
: CupertinoColors.darkBackgroundGray
),
child: new SafeArea(
child: new ListView(
children: new List<Widget> {
new Padding(padding: EdgeInsets.only(top: 32.0f)),
this._buildColorPicker(context),
this._buildCountdownTimerPicker(context),
this._buildDatePicker(context),
this._buildTimePicker(context),
this._buildDateAndTimePicker(context)
}
)
)
)
)
);
}
}
}

11
Samples/UIWidgetsGallery/demo/cupertino/cupertino_picker_demo.cs.meta


fileFormatVersion: 2
guid: 6cb09763e9a60447490569afa586f063
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存