浏览代码

Merge branch 'master' of gitlab.cds.internal.unity3d.com:upm-packages/ui-widgets/com.unity.uiwidgets into material

/main
xingwei.zhu 6 年前
当前提交
a2514811
共有 7 个文件被更改,包括 522 次插入351 次删除
  1. 3
      Runtime/widgets/banner.cs
  2. 2
      Runtime/widgets/framework.cs
  3. 667
      Samples/UIWidgetsGallery/demo/material/buttons_demo.cs
  4. 2
      Samples/UIWidgetsGallery/gallery/backdrop.cs
  5. 16
      Samples/UIWidgetsGallery/gallery/demos.cs
  6. 172
      Samples/UIWidgetsGallery/demo/colors_demo.cs
  7. 11
      Samples/UIWidgetsGallery/demo/colors_demo.cs.meta

3
Runtime/widgets/banner.cs


) {
D.assert(message != null);
D.assert(location != null);
D.assert(textStyle != null);
this.color = color ?? BannerConstants._kColor;
this.message = message;
this.location = location;

TextStyle textStyle = null
) : base(key: key) {
D.assert(message != null);
D.assert(color != null);
D.assert(textStyle != null);
this.child = child;
this.message = message;
this.location = location;

2
Runtime/widgets/framework.cs


}
public abstract class StatefulWidget : Widget {
protected StatefulWidget(Key key) : base(key: key) {
protected StatefulWidget(Key key = null) : base(key: key) {
}
public override Element createElement() {

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


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;

using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class ButtonsDemo : StatefulWidget {
public const string routeName = "/material/buttons";
class ButtonsDemo : StatefulWidget {
public const String routeName = "/material/buttons";
public ButtonsDemo(Key key = null) : base(key: key) {
}
public ButtonsDemo(Key key = null) : base(key: key) {
}
public override State createState() {
return new _ButtonsDemoState();
}
}
public override State createState() => new _ButtonsDemoState();
}
class _ButtonsDemoState : State<ButtonsDemo> {
const String _raisedText =
"Raised buttons add dimension to mostly flat layouts. They emphasize " +
class _ButtonsDemoState : State<ButtonsDemo> {
const string _raisedText =
"Raised buttons add dimension to mostly flat layouts. They emphasize " +
const String _raisedCode = "buttons_raised";
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 _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 _flatCode = "buttons_flat";
const String _outlineText =
"Outline buttons become opaque and elevate when pressed. They are often " +
const string _outlineText =
"Outline buttons become opaque and elevate when pressed. They are often " +
const String _outlineCode = "buttons_outline";
const string _outlineCode = "buttons_outline";
const String _dropdownText =
"A dropdown button displays a menu that's used to select a value from a " +
const string _dropdownText =
"A dropdown button displays a menu that's used to select a value from a " +
const String _dropdownCode = "buttons_dropdown";
const string _dropdownCode = "buttons_dropdown";
const String _iconText =
"IconButtons are appropriate for toggle buttons that allow a single choice " +
const string _iconText =
"IconButtons are appropriate for toggle buttons that allow a single choice " +
const String _iconCode = "buttons_icon";
const string _iconCode = "buttons_icon";
const String _actionText =
"Floating action buttons are used for a promoted action. They are " +
const string _actionText =
"Floating action buttons are used for a promoted action. They are " +
const String _actionCode = "buttons_action";
ShapeBorder _buttonShape;
const string _actionCode = "buttons_action";
public _ButtonsDemoState() {
}
ShapeBorder _buttonShape;
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context).copyWith(
shape: this._buttonShape
);
public _ButtonsDemoState() {
}
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"
)
};
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context).copyWith(
shape: this._buttonShape
);
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
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;
});
}
)
),
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(
public Widget buildRaisedButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
children: new List< Widget >{
new FlatButton(
child: new Text ("FLAT BUTTON"),
onPressed: () => {
// Perform some action
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 FlatButton (
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
)
}
),
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
)
);
}
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
),
),
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
)
}
)
}
)
);
}
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";
// 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"}.Select((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"}.Select((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()
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"}.Select((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"}.Select((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;
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 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"
)
);
}
}
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"
)
);
}
}
}

2
Samples/UIWidgetsGallery/gallery/backdrop.cs


Widget frontLayer = null,
Widget backTitle = null,
Widget backLayer = null
) : base(key: null) {
) {
this.frontAction = frontAction;
this.frontTitle = frontTitle;
this.frontHeading = frontHeading;

16
Samples/UIWidgetsGallery/gallery/demos.cs


// ),
//
// // Style
// new GalleryDemo(
// title: "Colors",
// subtitle: "All of the predefined colors",
// icon: GalleryIcons.colors,
// category: GalleryDemoCategory._kStyle,
// routeName: ColorsDemo.routeName,
// buildRoute: (BuildContext context) => ColorsDemo()
// ),
new GalleryDemo(
title: "Colors",
subtitle: "All of the predefined colors",
icon: GalleryIcons.colors,
category: DemoUtils._kStyle,
routeName: ColorsDemo.routeName,
buildRoute: (BuildContext context) => new ColorsDemo()
),
// new GalleryDemo(
// title: "Typography",
// subtitle: "All of the predefined text styles",

172
Samples/UIWidgetsGallery/demo/colors_demo.cs


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.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.gallery {
class ColorDemoConstants {
public const float kColorItemHeight = 48.0f;
public static readonly List<Palette> allPalettes = new List<Palette> {
new Palette(name: "RED", primary: Colors.red, accent: Colors.redAccent, threshold: 300),
new Palette(name: "PINK", primary: Colors.pink, accent: Colors.pinkAccent, threshold: 200),
new Palette(name: "PURPLE", primary: Colors.purple, accent: Colors.purpleAccent, threshold: 200),
new Palette(name: "DEEP PURPLE", primary: Colors.deepPurple, accent: Colors.deepPurpleAccent,
threshold: 200),
new Palette(name: "INDIGO", primary: Colors.indigo, accent: Colors.indigoAccent, threshold: 200),
new Palette(name: "BLUE", primary: Colors.blue, accent: Colors.blueAccent, threshold: 400),
new Palette(name: "LIGHT BLUE", primary: Colors.lightBlue, accent: Colors.lightBlueAccent, threshold: 500),
new Palette(name: "CYAN", primary: Colors.cyan, accent: Colors.cyanAccent, threshold: 600),
new Palette(name: "TEAL", primary: Colors.teal, accent: Colors.tealAccent, threshold: 400),
new Palette(name: "GREEN", primary: Colors.green, accent: Colors.greenAccent, threshold: 500),
new Palette(name: "LIGHT GREEN", primary: Colors.lightGreen, accent: Colors.lightGreenAccent,
threshold: 600),
new Palette(name: "LIME", primary: Colors.lime, accent: Colors.limeAccent, threshold: 800),
new Palette(name: "YELLOW", primary: Colors.yellow, accent: Colors.yellowAccent),
new Palette(name: "AMBER", primary: Colors.amber, accent: Colors.amberAccent),
new Palette(name: "ORANGE", primary: Colors.orange, accent: Colors.orangeAccent, threshold: 700),
new Palette(name: "DEEP ORANGE", primary: Colors.deepOrange, accent: Colors.deepOrangeAccent,
threshold: 400),
new Palette(name: "BROWN", primary: Colors.brown, threshold: 200),
new Palette(name: "GREY", primary: Colors.grey, threshold: 500),
new Palette(name: "BLUE GREY", primary: Colors.blueGrey, threshold: 500),
};
}
public class Palette {
public Palette(string name = null, MaterialColor primary = null, MaterialAccentColor accent = null,
int threshold = 900) {
this.name = name;
this.primary = primary;
this.accent = accent;
this.threshold = threshold;
}
public readonly string name;
public readonly MaterialColor primary;
public readonly MaterialAccentColor accent;
public readonly int threshold;
public bool isValid {
get { return this.name != null && this.primary != null && this.threshold != null; }
}
}
public class ColorItem : StatelessWidget {
public ColorItem(
Key key = null,
int? index = null,
Color color = null,
string prefix = ""
) : base(key: key) {
D.assert(index != null);
D.assert(color != null);
D.assert(prefix != null);
this.index = index;
this.color = color;
this.prefix = prefix;
}
public readonly int? index;
public readonly Color color;
public readonly string prefix;
string colorString() {
return $"#{this.color.value.ToString("X8").ToUpper()}";
}
public override Widget build(BuildContext context) {
return new Container(
height: ColorDemoConstants.kColorItemHeight,
padding: EdgeInsets.symmetric(horizontal: 16.0f),
color: this.color,
child: new SafeArea(
top: false,
bottom: false,
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget> {
new Text($"{this.prefix}{this.index}"),
new Text(this.colorString())
}
)
)
);
}
}
public class PaletteTabView : StatelessWidget {
public PaletteTabView(
Key key = null,
Palette colors = null
) : base(key: key) {
D.assert(colors != null && colors.isValid);
this.colors = colors;
}
public readonly Palette colors;
public readonly static List<int> primaryKeys = new List<int> {50, 100, 200, 300, 400, 500, 600, 700, 800, 900};
public readonly static List<int> accentKeys = new List<int> {100, 200, 400, 700};
public override Widget build(BuildContext context) {
TextTheme textTheme = Theme.of(context).textTheme;
TextStyle whiteTextStyle = textTheme.body1.copyWith(color: Colors.white);
TextStyle blackTextStyle = textTheme.body1.copyWith(color: Colors.black);
List<Widget> colorItems = primaryKeys.Select<int, Widget>((int index) => {
return new DefaultTextStyle(
style: index > this.colors.threshold ? whiteTextStyle : blackTextStyle,
child: new ColorItem(index: index, color: this.colors.primary[index])
);
}).ToList();
if (this.colors.accent != null) {
colorItems.AddRange(accentKeys.Select<int, Widget>((int index) => {
return new DefaultTextStyle(
style: index > this.colors.threshold ? whiteTextStyle : blackTextStyle,
child: new ColorItem(index: index, color: this.colors.accent[index], prefix: "A")
);
}).ToList());
}
return new ListView(
itemExtent: ColorDemoConstants.kColorItemHeight,
children: colorItems
);
}
}
public class ColorsDemo : StatelessWidget {
public const string routeName = "/colors";
public override Widget build(BuildContext context) {
return new DefaultTabController(
length: ColorDemoConstants.allPalettes.Count,
child: new Scaffold(
appBar: new AppBar(
elevation: 0.0f,
title: new Text("Colors"),
bottom: new TabBar(
isScrollable: true,
tabs: ColorDemoConstants.allPalettes
.Select<Palette, Widget>((Palette swatch) => new Tab(text: swatch.name)).ToList()
)
),
body: new TabBarView(
children: ColorDemoConstants.allPalettes.Select<Palette, Widget>((Palette colors) => {
return new PaletteTabView(colors: colors);
}).ToList()
)
)
);
}
}
}

11
Samples/UIWidgetsGallery/demo/colors_demo.cs.meta


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