浏览代码

add demo

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
58cac1fc
共有 9 个文件被更改,包括 539 次插入15 次删除
  1. 4
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/cupertino/cupertino_navigation_demo.cs
  2. 6
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/drawer_demo.cs
  3. 40
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs
  4. 6
      com.unity.uiwidgets/Runtime/material/bottom_sheet.cs
  5. 43
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/modal_bottom_sheet_demo.cs
  6. 103
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/persistent_bottom_sheet_demo.cs
  7. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/persistent_bottom_sheet_demo.cs.meta
  8. 346
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/search_demo.cs
  9. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/search_demo.cs.meta

4
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/cupertino/cupertino_navigation_demo.cs


decoration: new BoxDecoration(
image: new DecorationImage(
image: new FileImage(
file: "people/square/trevor.png"
file: "gallery/people/square/trevor.png"
)
),
shape: BoxShape.circle

decoration: new BoxDecoration(
image: new DecorationImage(
image: new FileImage(
"people/square/sandra.png"
"gallery/people/square/sandra.png"
)
),
shape: BoxShape.circle

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


{
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 _kAsset0 = "gallery/people/square/trevor.png";
public static readonly string _kAsset1 = "gallery/people/square/stella.png";
public static readonly string _kAsset2 = "gallery/people/square/sandra.png";
public static readonly string _kGalleryAssetsPackage = "flutter_gallery_assets";
}

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


using UIWidgetsGallery.demo;
using UIWidgetsGallery.demo.material;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.widgets;
using UnityEngine;

public static List<GalleryDemo> _buildGalleryDemos()
{
List<GalleryDemo> cupertinoDemos = new List<GalleryDemo>()
List<GalleryDemo> galleryDemos = new List<GalleryDemo>()
{
new GalleryDemo(
title: "Activity Indicator",

category:GalleryDemoCategory._kCupertinoComponents,
routeName: CupertinoTextFieldDemo.routeName,
buildRoute: (BuildContext context) => new CupertinoTextFieldDemo()
)
};
List<GalleryDemo> galleryDemos = new List<GalleryDemo>
{
),
new GalleryDemo(
title: "Shrine",
subtitle: "Basic shopping app",

buildRoute: (BuildContext context) => new BottomNavigationDemo()
),
new GalleryDemo(
title: "Bottom sheet: Modal",
subtitle: "A dismissable bottom sheet",
icon: GalleryIcons.bottom_sheets,
category: GalleryDemoCategory._kMaterialComponents,
routeName: ModalBottomSheetDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/showModalBottomSheet.html",
buildRoute: (BuildContext context) => new ModalBottomSheetDemo()
),
new GalleryDemo(
title: "Bottom sheet: Persistent",
subtitle: "A bottom sheet that sticks around",
icon: GalleryIcons.bottom_sheet_persistent,
category: GalleryDemoCategory._kMaterialComponents,
routeName: PersistentBottomSheetDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/ScaffoldState/showBottomSheet.html",
buildRoute: (BuildContext context) => new PersistentBottomSheetDemo()
),
new GalleryDemo(
title: "Buttons",
subtitle: "Flat, raised, dropdown, and more",
icon: GalleryIcons.generic_buttons,

buildRoute: (BuildContext context) => new DataTableDemo()
),
new GalleryDemo(
title: "Search",
subtitle: "Expandable search",
icon: Icons.search,
category: GalleryDemoCategory._kMaterialComponents,
routeName: SearchDemo.routeName,
documentationUrl: "https://docs.flutter.io/flutter/material/showSearch.html",
buildRoute: (BuildContext context) => new SearchDemo()
),
new GalleryDemo(
title: "Dialogs",
subtitle: "Simple, alert, and fullscreen",
icon: GalleryIcons.dialogs,

buildRoute: (BuildContext context) => new DrawerDemo()
),
};
cupertinoDemos.AddRange(galleryDemos);
return cupertinoDemos;
return galleryDemos;
}
public static readonly List<GalleryDemo> kAllGalleryDemos = _buildGalleryDemos();

6
com.unity.uiwidgets/Runtime/material/bottom_sheet.cs


public partial class material_ {
public static readonly TimeSpan _bottomSheetEnterDuration = new TimeSpan(0, 0, 0, 0, 250);
public static readonly TimeSpan _bottomSheetExitDuration = new TimeSpan(0, 0, 0, 0, 200);
public static readonly Curve _modalBottomSheetCurve = material_.decelerateEasing;
public static Curve _modalBottomSheetCurve {
get => decelerateEasing;
}
public const float _minFlingVelocity = 700.0f;
public const float _closeProgressThreshold = 0.5f;

43
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/modal_bottom_sheet_demo.cs


using System.Collections.Generic;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.gallery {
public class ModalBottomSheetDemo : StatelessWidget {
public const string routeName = "/material/modal-bottom-sheet";
public override Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Modal bottom sheet"),
actions: new List<Widget> {new MaterialDemoDocumentationButton(routeName)}
),
body: new Center(
child: new RaisedButton(
child: new Text("SHOW BOTTOM SHEET"),
onPressed: () => {
material_.showModalBottomSheet<object>(context: context,
builder: (BuildContext _context) => {
return new Container(
child: new Padding(
padding: EdgeInsets.all(32.0f),
child: new Text("This is the modal bottom sheet. Tap anywhere to dismiss.",
textAlign: TextAlign.center,
style: new TextStyle(
color: Theme.of(_context).accentColor,
fontSize: 24.0f
)
)
)
);
});
}
)
)
);
}
}
}

103
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/persistent_bottom_sheet_demo.cs


using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.gallery {
public class PersistentBottomSheetDemo : StatefulWidget {
public const string routeName = "/material/persistent-bottom-sheet";
public override State createState() {
return new _PersistentBottomSheetDemoState();
}
}
class _PersistentBottomSheetDemoState : State<PersistentBottomSheetDemo> {
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
VoidCallback _showBottomSheetCallback;
public override void initState() {
base.initState();
this._showBottomSheetCallback = this._showBottomSheet;
}
void _showBottomSheet() {
this.setState(() => {
// disable the button
this._showBottomSheetCallback = null;
});
this._scaffoldKey.currentState.showBottomSheet((BuildContext context) => {
ThemeData themeData = Theme.of(this.context);
return new Container(
decoration: new BoxDecoration(
border: new Border(top: new BorderSide(color: themeData.disabledColor))
),
child: new Padding(
padding: EdgeInsets.all(32.0f),
child: new Text("This is a Material persistent bottom sheet. Drag downwards to dismiss it.",
textAlign: TextAlign.center,
style: new TextStyle(
color: themeData.accentColor,
fontSize: 24.0f
)
)
)
);
})
.closed.then((value) => {
if (this.mounted) {
this.setState(() => {
// re-enable the button
this._showBottomSheetCallback = this._showBottomSheet;
});
}
});
}
void _showMessage() {
DialogUtils.showGeneralDialog<object>(
context: this.context,
pageBuilder: ( context, _, __) => {
return new AlertDialog(
content: new Text("You tapped the floating action button."),
actions: new List<Widget> {
new FlatButton(
onPressed: () => { Navigator.pop(context); },
child: new Text("OK")
)
}
);
}
);
}
public override Widget build(BuildContext context) {
return new Scaffold(
key: this._scaffoldKey,
appBar: new AppBar(
title: new Text("Persistent bottom sheet"),
actions: new List<Widget> {
new MaterialDemoDocumentationButton(PersistentBottomSheetDemo.routeName)
}
),
floatingActionButton: new FloatingActionButton(
onPressed: this._showMessage,
backgroundColor: Colors.redAccent,
child: new Icon(
Icons.add
)
),
body: new Center(
child: new RaisedButton(
onPressed: this._showBottomSheetCallback,
child: new Text("SHOW BOTTOM SHEET")
)
)
);
}
}
}

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


fileFormatVersion: 2
guid: c949d1ae2a444ef085b83e1a0db18cc9
timeCreated: 1612683278

346
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/material/search_demo.cs


using System;
using System.Collections.Generic;
using uiwidgets;
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 UnityEngine;
namespace UIWidgetsGallery.gallery {
public class SearchDemo : StatefulWidget {
public const string routeName = "/material/search";
public override State createState() {
return new _SearchDemoState();
}
}
class _SearchDemoState : State<SearchDemo> {
readonly _SearchDemoSearchDelegate _delegate = new _SearchDemoSearchDelegate();
readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
int? _lastIntegerSelected;
public override Widget build(BuildContext context) {
return new Scaffold(
key: this._scaffoldKey,
appBar: new AppBar(
leading: new IconButton(
tooltip: "Navigation menu",
icon: new AnimatedIcon(
icon: AnimatedIcons.arrow_menu,
color: Colors.white,
progress: this._delegate.transitionAnimation
),
onPressed: () => { this._scaffoldKey.currentState.openDrawer(); }
),
title: new Text("Numbers"),
actions: new List<Widget> {
new IconButton(
tooltip: "Search",
icon: new Icon(Icons.search),
onPressed: () => {
SearchUtils.showSearch(
context: context,
del: this._delegate
).then_((selected) => {
if (selected != null && (int) selected != this._lastIntegerSelected) {
this.setState(() => { this._lastIntegerSelected = (int) selected; });
}
});
}
),
new MaterialDemoDocumentationButton(SearchDemo.routeName),
new IconButton(
tooltip: "More (not implemented)",
icon: new Icon(
Theme.of(context).platform == RuntimePlatform.IPhonePlayer
? Icons.more_horiz
: Icons.more_vert
),
onPressed: () => { }
)
}
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget> {
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget> {
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget> {
new Text("Press the "),
new Tooltip(
message: "search",
child: new Icon(
Icons.search,
size: 18.0f
)
),
new Text(" icon in the AppBar")
}
),
new Text("and search for an integer between 0 and 100,000.")
}
),
new SizedBox(height: 64.0f),
new Text(
this._lastIntegerSelected == null
? $"Last selected integer: {this._lastIntegerSelected}."
: $"Last selected integer: NONE."
),
}
)
),
floatingActionButton: FloatingActionButton.extended(
tooltip: "Back", // Tests depend on this label to exit the demo.
onPressed: () => { Navigator.of(context).pop<object>(); },
label:
new Text("Close demo"),
icon:
new Icon(Icons.close)
),
drawer: new Drawer(
child: new Column(
children: new List<Widget> {
new UserAccountsDrawerHeader(
accountName: new Text("Peter Widget"),
accountEmail: new Text("peter.widget@example.com"),
currentAccountPicture: new CircleAvatar(
backgroundImage: new FileImage(
"gallery/people/square/peter.png"
)
),
margin: EdgeInsets.zero
),
MediaQuery.removePadding(
context: context,
// DrawerHeader consumes top MediaQuery padding.
removeTop: true,
child: new ListTile(
leading: new Icon(Icons.payment),
title: new Text("Placeholder")
)
)
}
)
)
);
}
}
class _SearchDemoSearchDelegate : SearchDelegate<int>
{
static List<int> listGenerate(int count, Func<int, int> func) {
var list = new List<int>();
for (int i = 0; i < count; i++) {
list.Add(func(i));
}
list.Reverse();
return list;
}
readonly List<int> _data = listGenerate(100001, (int i) => i);
readonly List<int> _history = new List<int> {42607, 85604, 66374, 44, 174};
public override Widget buildLeading(BuildContext context) {
return new IconButton(
tooltip: "Back",
icon: new AnimatedIcon(
icon: AnimatedIcons.arrow_menu,
progress: this.transitionAnimation
),
onPressed: () => { this.close(context, null); }
);
}
public override Widget buildSuggestions(BuildContext context) {
List<int> suggestions;
if (this.query.isEmpty()) {
suggestions = this._history;
}
else {
suggestions = new List<int>();
foreach (var item in this._data) {
var str = item.ToString();
var flag = true;
if (str.Length < this.query.Length) {
continue;
}
for (int i = 0; i < this.query.Length; i++) {
if (str[i] != this.query[i]) {
flag = false;
break;
}
}
if (flag) {
suggestions.Add(item);
}
}
}
List<string> suggestionStrings = new List<string>();
foreach (var item in suggestions) {
suggestionStrings.Add(item.ToString());
}
return new _SuggestionList(
query: this.query,
suggestions: suggestionStrings,
onSelected: (string suggestion) => {
this.query = suggestion;
this.showResults(context);
}
);
}
public override Widget buildResults(BuildContext context) {
int searched;
try {
searched = int.Parse(this.query);
}
catch (Exception) {
return new Center(
child: new Text(
$"{this.query}\n is not a valid integer between 0 and 100,000.\nTry again.",
textAlign: TextAlign.center
)
);
}
if (!this._data.Contains(searched)) {
return new Center(
child: new Text(
$"{this.query}\n is not a valid integer between 0 and 100,000.\nTry again.",
textAlign: TextAlign.center
)
);
}
return new ListView(
children: new List<Widget> {
new _ResultCard(
title: "This integer",
integer: searched,
searchDelegate: this
),
new _ResultCard(
title: "Next integer",
integer: searched + 1,
searchDelegate: this
),
new _ResultCard(
title: "Previous integer",
integer: searched - 1,
searchDelegate: this
)
}
);
}
public override List<Widget> buildActions(BuildContext context) {
return new List<Widget> {
this.query.isEmpty()
? new IconButton(
tooltip: "Voice Search",
icon: new Icon(Icons.mic),
onPressed: () => { this.query = "TODO: implement voice input"; }
)
: new IconButton(
tooltip: "Clear",
icon: new Icon(Icons.clear),
onPressed:
() => {
this.query = "";
this.showSuggestions(context);
}
)
};
}
}
class _ResultCard : StatelessWidget {
public _ResultCard(
int integer, string title, SearchDelegate<int> searchDelegate
) {
this.integer = integer;
this.title = title;
this.searchDelegate = searchDelegate;
}
public readonly int integer;
public readonly string title;
public readonly SearchDelegate<int> searchDelegate;
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
return new GestureDetector(
onTap: () => { this.searchDelegate.close(context, this.integer); },
child:
new Card(
child: new Padding(
padding: EdgeInsets.all(8.0f),
child: new Column(
children: new List<Widget> {
new Text(this.title),
new Text(this.integer.ToString(),
style: theme.textTheme.headline.copyWith(fontSize: 72.0f)
),
}
)
)
)
);
}
}
class _SuggestionList : StatelessWidget {
public _SuggestionList(
List<string> suggestions, string query, ValueChanged<string> onSelected
) {
this.suggestions = suggestions;
this.query = query;
this.onSelected = onSelected;
}
public readonly List<string> suggestions;
public readonly string query;
public readonly ValueChanged<string> onSelected;
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
return ListView.builder(
itemCount: this.suggestions.Count,
itemBuilder: (BuildContext _context, int i) => {
string suggestion = this.suggestions[i];
return new ListTile(
leading: this.query.isEmpty() ? new Icon(Icons.history) : new Icon(null),
title: new RichText(
text: new TextSpan(
text: suggestion.Substring(0, this.query.Length),
style: theme.textTheme.subhead.copyWith(fontWeight: FontWeight.bold),
children: new List<InlineSpan>
{
new TextSpan(
text: suggestion.Substring(this.query.Length),
style: theme.textTheme.subhead
)
}
)
),
onTap: () => { this.onSelected(suggestion); }
);
}
);
}
}
}

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


fileFormatVersion: 2
guid: 958332d4fa614f18b3d446a66cc0f93d
timeCreated: 1612682743
正在加载...
取消
保存