浏览代码

Temp store.

/main
Yuncong Zhang 6 年前
当前提交
e4d6d823
共有 10 个文件被更改,包括 699 次插入0 次删除
  1. 8
      Samples/UIWidgetsGallery/demo.meta
  2. 217
      Samples/UIWidgetsGallery/gallery/demo.cs
  3. 3
      Samples/UIWidgetsGallery/gallery/demo.cs.meta
  4. 58
      Samples/UIWidgetsGallery/gallery/example_code_parser.cs
  5. 3
      Samples/UIWidgetsGallery/gallery/example_code_parser.cs.meta
  6. 8
      Samples/UIWidgetsGallery/demo/material.meta
  7. 391
      Samples/UIWidgetsGallery/demo/material/buttons_demo.cs
  8. 11
      Samples/UIWidgetsGallery/demo/material/buttons_demo.cs.meta

8
Samples/UIWidgetsGallery/demo.meta


fileFormatVersion: 2
guid: 5159692a5f76049d49b05fb717c096e3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

217
Samples/UIWidgetsGallery/gallery/demo.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class ComponentDemoTabData {
public ComponentDemoTabData(
Widget demoWidget = null,
string exampleCodeTag = null,
string description = null,
string tabName = null,
string documentationUrl = null
) {
this.demoWidget = demoWidget;
this.exampleCodeTag = exampleCodeTag;
this.description = description;
this.tabName = tabName;
this.documentationUrl = documentationUrl;
}
public readonly Widget demoWidget;
public readonly string exampleCodeTag;
public readonly string description;
public readonly string tabName;
public readonly string documentationUrl;
public static bool operator ==(ComponentDemoTabData left, ComponentDemoTabData right) {
return right.tabName == left.tabName
&& right.description == left.description
&& right.documentationUrl == left.documentationUrl;
}
public static bool operator !=(ComponentDemoTabData left, ComponentDemoTabData right) {
return right.tabName != left.tabName
|| right.description != left.description
|| right.documentationUrl != left.documentationUrl;
}
public override int GetHashCode() {
unchecked {
var hashCode = this.tabName.GetHashCode();
hashCode = (hashCode * 397) ^ this.description.GetHashCode();
hashCode = (hashCode * 397) ^ this.documentationUrl.GetHashCode();
return hashCode;
}
}
}
class TabbedComponentDemoScaffold : StatelessWidget {
public TabbedComponentDemoScaffold(
string title = null,
List<ComponentDemoTabData> demos = null,
List<Widget> actions = null
) {
this.title = title;
this.demos = demos;
this.actions = actions;
}
public readonly List<ComponentDemoTabData> demos;
public readonly string title;
public readonly List<Widget> actions;
void _showExampleCode(BuildContext context) {
string tag = this.demos[DefaultTabController.of(context).index].exampleCodeTag;
if (tag != null) {
Navigator.push(context, new MaterialPageRoute(
builder: (BuildContext _context) => new FullScreenCodeDialog(exampleCodeTag: tag)
));
}
}
void _showApiDocumentation(BuildContext context) {
string url = this.demos[DefaultTabController.of(context).index].documentationUrl;
if (url != null) {
// TODO: find Unity equivalent
// Open the URL in browser
// launch(url, forceWebView: true);
}
}
public override Widget build(BuildContext context) {
List<Widget> actions = this.actions ?? new List<Widget> { };
actions.AddRange(
new List<Widget> {
new Builder(
builder: (BuildContext _context) => {
return new IconButton(
icon: new Icon(Icons.library_books),
onPressed: () => this._showApiDocumentation(_context)
);
}
),
new Builder(
builder: (BuildContext _context) => {
return new IconButton(
icon: new Icon(Icons.code),
tooltip: "Show example code",
onPressed: () => this._showExampleCode(_context)
);
}
)
}
);
return new DefaultTabController(
length: this.demos.Count,
child: new Scaffold(
appBar: new AppBar(
title: new Text(this.title),
actions: actions,
bottom: new TabBar(
isScrollable: true,
tabs: this.demos.Select<ComponentDemoTabData, Widget>(
(ComponentDemoTabData data) => new Tab(text: data.tabName))
.ToList()
)
),
body: new TabBarView(
children: this.demos.Select<ComponentDemoTabData, Widget>((ComponentDemoTabData demo) => {
return new SafeArea(
top: false,
bottom: false,
child: new Column(
children: new List<Widget> {
new Padding(
padding: EdgeInsets.all(16.0f),
child: new Text(demo.description,
style: Theme.of(context).textTheme.subhead
)
),
new Expanded(child: demo.demoWidget)
}
)
);
}).ToList()
)
)
);
}
}
class FullScreenCodeDialog : StatefulWidget {
public FullScreenCodeDialog(Key key = null, string exampleCodeTag = null) : base(key: key) {
this.exampleCodeTag = exampleCodeTag;
}
public readonly string exampleCodeTag;
public override State createState() {
return new FullScreenCodeDialogState();
}
}
class FullScreenCodeDialogState : State<FullScreenCodeDialog> {
public FullScreenCodeDialogState() {
}
string _exampleCode;
public override void didChangeDependencies() {
getExampleCode(this.widget.exampleCodeTag, DefaultAssetBundle.of(this.context)).then<void>(
(string code) => {
if (this.mounted) {
this.setState(() => { this._exampleCode = code ?? "Example code not found"; });
}
});
base.didChangeDependencies();
}
public override Widget build(BuildContext context) {
SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark
? SyntaxHighlighterStyle.darkThemeStyle()
: SyntaxHighlighterStyle.lightThemeStyle();
Widget body;
if (this._exampleCode == null) {
body = new Center(
child: CircularProgressIndicator()
);
}
else {
body = new SingleChildScrollView(
child: new Padding(
padding: EdgeInsets.all(16.0f),
child: new RichText(
text: new TextSpan(
style: new TextStyle(fontFamily: "monospace", fontSize: 10.0f),
children: new List<TextSpan> {
DartSyntaxHighlighter(style).format(this._exampleCode)
}
)
)
)
);
}
return new Scaffold(
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(
Icons.clear
),
onPressed: () => { Navigator.pop(context); }
),
title: new Text("Example code")
),
body: body
);
}
}
}

3
Samples/UIWidgetsGallery/gallery/demo.cs.meta


fileFormatVersion: 2
guid: 3c8404e1b03d43aba2e91d19f124de5e
timeCreated: 1552462303

58
Samples/UIWidgetsGallery/gallery/example_code_parser.cs


using System;
using System.Collections.Generic;
using RSG;
using UnityEngine;
namespace UIWidgetsGallery.gallery {
public class ExampleCodeParser {
const string _kStartTag = "// START ";
const string _kEndTag = "// END";
Dictionary<string, string> _exampleCode;
async IPromise<string> getExampleCode(string tag, AssetBundle bundle) {
if (_exampleCode == null)
await _parseExampleCode(bundle);
return _exampleCode[tag];
}
Future<void> _parseExampleCode(AssetBundle bundle) async {
final String code = await bundle.loadString("lib/gallery/example_code.dart") ??
"// lib/gallery/example_code.dart not found\n";
_exampleCode = <String, String>{};
final List<String> lines = code.split("\n");
List<String> codeBlock;
String codeTag;
for (String line in lines) {
if (codeBlock == null) {
// Outside a block.
if (line.startsWith(_kStartTag)) {
// Starting a new code block.
codeBlock = <String>[];
codeTag = line.substring(_kStartTag.length).trim();
} else {
// Just skipping the line.
}
} else {
// Inside a block.
if (line.startsWith(_kEndTag)) {
// Add the block.
_exampleCode[codeTag] = codeBlock.join("\n");
codeBlock = null;
codeTag = null;
} else {
// Add to the current block
// trimRight() to remove any \r on Windows
// without removing any useful indentation
codeBlock.add(line.trimRight());
}
}
}
}
}
}

3
Samples/UIWidgetsGallery/gallery/example_code_parser.cs.meta


fileFormatVersion: 2
guid: 57879fd6125746699974c2e0bc8762b8
timeCreated: 1552468268

8
Samples/UIWidgetsGallery/demo/material.meta


fileFormatVersion: 2
guid: edc3bae86553f44c2b7e7fddbf6cb497
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

391
Samples/UIWidgetsGallery/demo/material/buttons_demo.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class ButtonsDemo : StatefulWidget {
const String routeName = "/material/buttons";
public ButtonsDemo(Key key = null) : base(key: key) {
}
public override State createState() => new _ButtonsDemoState();
}
class _ButtonsDemoState : State<ButtonsDemo> {
const String _raisedText =
"Raised buttons add dimension to mostly flat layouts. They emphasize " +
"functions on busy or wide spaces.";
const String _raisedCode = "buttons_raised";
const String _flatText = "A flat button displays an ink splash on press " +
"but does not lift. Use flat buttons on toolbars, in dialogs and " +
"inline with padding";
const String _flatCode = "buttons_flat";
const String _outlineText =
"Outline buttons become opaque and elevate when pressed. They are often " +
"paired with raised buttons to indicate an alternative, secondary action.";
const String _outlineCode = "buttons_outline";
const String _dropdownText =
"A dropdown button displays a menu that\"s used to select a value from a " +
"small set of values. The button displays the current value and a down " +
"arrow.";
const String _dropdownCode = "buttons_dropdown";
const String _iconText =
"IconButtons are appropriate for toggle buttons that allow a single choice " +
"to be selected or deselected, such as adding or removing an item\"s star.";
const String _iconCode = "buttons_icon";
const String _actionText =
"Floating action buttons are used for a promoted action. They are " +
"distinguished by a circled icon floating above the UI and can have motion " +
"behaviors that include morphing, launching, and a transferring anchor " +
"point.";
const String _actionCode = "buttons_action";
ShapeBorder _buttonShape;
public _ButtonsDemoState() {
}
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context).copyWith(
shape: this._buttonShape
);
List<ComponentDemoTabData> demos = new List<ComponentDemoTabData>{
new ComponentDemoTabData(
tabName: "RAISED",
description: _raisedText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildRaisedButton()
),
exampleCodeTag: _raisedCode,
documentationUrl: "https://docs.flutter.io/flutter/material/RaisedButton-class.html"
),
new ComponentDemoTabData(
tabName: "FLAT",
description: _flatText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildFlatButton()
),
exampleCodeTag: _flatCode,
documentationUrl: "https://docs.flutter.io/flutter/material/FlatButton-class.html"
),
new ComponentDemoTabData(
tabName: "OUTLINE",
description: _outlineText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildOutlineButton()
),
exampleCodeTag: _outlineCode,
documentationUrl: "https://docs.flutter.io/flutter/material/OutlineButton-class.html"
),
new ComponentDemoTabData(
tabName: "DROPDOWN",
description: _dropdownText,
demoWidget: this.buildDropdownButton(),
exampleCodeTag: _dropdownCode,
documentationUrl: "https://docs.flutter.io/flutter/material/DropdownButton-class.html"
),
new ComponentDemoTabData(
tabName: "ICON",
description: _iconText,
demoWidget: this.buildIconButton(),
exampleCodeTag: _iconCode,
documentationUrl: "https://docs.flutter.io/flutter/material/IconButton-class.html"
),
new ComponentDemoTabData(
tabName: "ACTION",
description: _actionText,
demoWidget: this.buildActionButton(),
exampleCodeTag: _actionCode,
documentationUrl: "https://docs.flutter.io/flutter/material/FloatingActionButton-class.html"
)
};
return new TabbedComponentDemoScaffold(
title: "Buttons",
demos: demos,
actions: new List<Widget>{
new IconButton(
icon: new Icon(Icons.sentiment_very_satisfied),
onPressed: () => {
this.setState(() => {
this._buttonShape = this._buttonShape == null ? new StadiumBorder() : null;
});
}
)
}
);
}
public Widget buildRaisedButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>{
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>{
new RaisedButton(
child: new Text("RAISED BUTTON"),
onPressed: () => {
// Perform some action
}
),
new RaisedButton(
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>{
RaisedButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("RAISED BUTTON"),
onPressed: () => {
// Perform some action
}
),
RaisedButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("DISABLED"),
onPressed: null
)
}
)
}
)
);
}
public Widget buildFlatButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List< Widget >{
new FlatButton(
child: new Text ("FLAT BUTTON"),
onPressed: () => {
// Perform some action
}
),
new FlatButton (
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget>{
FlatButton.icon(
icon: new Icon(Icons.add_circle_outline, size: 18.0f),
label: new Text ("FLAT BUTTON"),
onPressed: () => {
// Perform some action
}
),
FlatButton.icon(
icon: new Icon (Icons.add_circle_outline, size: 18.0f),
label: new Text ("DISABLED"),
onPressed: null
),
}
)
}
)
);
}
Widget buildOutlineButton() {
return new Align(
alignment: new Alignment (0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new OutlineButton(
child: new Text("OUTLINE BUTTON"),
onPressed: () => {
// Perform some action
}
),
new OutlineButton(
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
OutlineButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("OUTLINE BUTTON"),
onPressed: () => {
// Perform some action
}
),
OutlineButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("DISABLED"),
onPressed: null
)
}
)
}
)
);
}
// https://en.wikipedia.org/wiki/Free_Four
string dropdown1Value = "Free";
string dropdown2Value;
string dropdown3Value = "Four";
public Widget buildDropdownButton() {
return new Padding(
padding: EdgeInsets.all(24.0f),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: new List < Widget > {
new ListTile(
title: new Text ("Simple dropdown:"),
trailing: new DropdownButton<string>(
value: this.dropdown1Value,
onChanged: (string newValue) => {
this.setState(() => {
this.dropdown1Value = newValue;
});
},
items: new List<string> {"One", "Two", "Free", "Four"}.map<DropdownMenuItem<String>>((string value) => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).toList()
)
),
new SizedBox (
height: 24.0f
),
new ListTile(
title: new Text ("Dropdown with a hint:"),
trailing: new DropdownButton<string>(
value: this.dropdown2Value,
hint: new Text ("Choose"),
onChanged: (string newValue) => {
this.setState(() => {
this.dropdown2Value = newValue;
});
},
items: new List<String >{"One", "Two", "Free", "Four"}.map<DropdownMenuItem<String>>((string value) => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).toList()
)
),
new SizedBox (
height: 24.0f
),
new ListTile(
title: new Text ("Scrollable dropdown:"),
trailing: new DropdownButton<string>(
value: this.dropdown3Value,
onChanged: (string newValue) => {
this.setState(() => {
this.dropdown3Value = newValue;
});
},
items: new List <String >{
"One", "Two", "Free", "Four", "Can", "I", "Have", "A", "Little",
"Bit", "More", "Five", "Six", "Seven", "Eight", "Nine", "Ten"
}.Select<string, DropdownMenuItem<string>>(value => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).ToList()
)
)
}
)
);
}
bool iconButtonToggle = false;
public Widget buildIconButton() {
return new Align(
alignment: new Alignment (0.0f, -0.2f),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List< Widget >{
new IconButton(
icon: new Icon (
Icons.thumb_up
),
onPressed: () => { this.setState(() => this.iconButtonToggle = !this.iconButtonToggle); },
color: this.iconButtonToggle ? Theme.of(this.context).primaryColor : null
),
new IconButton(
icon: new Icon(
Icons.thumb_up
),
onPressed: null
)
}.Select<Widget, Widget>((Widget button) => new SizedBox(width: 64.0f, height: 64.0f, child: button)).ToList()
)
);
}
public Widget buildActionButton() {
return new Align(
alignment: new Alignment (0.0f, -0.2f),
child: new FloatingActionButton(
child: new Icon(Icons.add),
onPressed: () => {
// Perform some action
},
tooltip: "floating action button"
)
);
}
}
}

11
Samples/UIWidgetsGallery/demo/material/buttons_demo.cs.meta


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