浏览代码

Merge branch 'kgdev' into 'master'

more materials.

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!102
/main
Xingwei Zhu 6 年前
当前提交
2d79eef4
共有 33 个文件被更改,包括 3033 次插入59 次删除
  1. 10
      Runtime/material/constants.cs
  2. 53
      Runtime/material/debug.cs
  3. 5
      Runtime/material/dialog.cs
  4. 2
      Runtime/material/drawer_header.cs
  5. 2
      Runtime/material/expand_icon.cs
  6. 2
      Runtime/material/icon_button.cs
  7. 2
      Runtime/material/ink_decoration.cs
  8. 2
      Runtime/material/ink_well.cs
  9. 2
      Runtime/material/list_tile.cs
  10. 4
      Runtime/material/page.cs
  11. 20
      Runtime/material/theme_data.cs
  12. 1
      Runtime/painting/image_resolution.cs
  13. 4
      Runtime/ui/geometry.cs
  14. 67
      Runtime/widgets/basic.cs
  15. 30
      Runtime/widgets/debug.cs
  16. 4
      Runtime/widgets/pages.cs
  17. 11
      Runtime/widgets/routes.cs
  18. 1
      Samples/UIWidgetSample/NavigationSample.cs
  19. 21
      Samples/UIWidgetsGallery/gallery/app.cs
  20. 17
      Samples/UIWidgetsGallery/gallery/demos.cs
  21. 365
      Samples/UIWidgetsGallery/gallery/options.cs
  22. 390
      Runtime/material/material_localizations.cs
  23. 11
      Runtime/material/material_localizations.cs.meta
  24. 608
      Runtime/material/popup_menu.cs
  25. 11
      Runtime/material/popup_menu.cs.meta
  26. 527
      Runtime/material/switch.cs
  27. 11
      Runtime/material/switch.cs.meta
  28. 153
      Runtime/material/timer.cs
  29. 11
      Runtime/material/timer.cs.meta
  30. 323
      Runtime/widgets/localizations.cs
  31. 11
      Runtime/widgets/localizations.cs.meta
  32. 400
      Samples/UIWidgetsGallery/gallery/home.cs
  33. 11
      Samples/UIWidgetsGallery/gallery/home.cs.meta

10
Runtime/material/constants.cs


namespace Unity.UIWidgets.material {
public static class Constants {
public static readonly float kToolbarHeight = 56.0f;
public const float kToolbarHeight = 56.0f;
public static readonly float kBottomNavigationBarHeight = 56.0f;
public const float kBottomNavigationBarHeight = 56.0f;
public static readonly float kTextTabBarHeight = 48.0f;
public const float kTextTabBarHeight = 48.0f;
public static readonly float kRadialReactionRadius = 20.0f;
public const float kRadialReactionRadius = 20.0f;
public static readonly int kRadialReactionAlpha = 0x1F;
public const int kRadialReactionAlpha = 0x1F;
public static readonly TimeSpan kTabScrollDuration = new TimeSpan(0, 0, 0, 0, 300);

53
Runtime/material/debug.cs


using System.Collections.Generic;
using System.Text;
public static class MaterialDebug {
public static class MaterialD {
public static bool debugCheckHasMaterial(BuildContext context) {
D.assert(() => {
if (!(context.widget is Material) && context.ancestorWidgetOfExactType(typeof(Material)) == null) {

message += "In material design, most widgets are conceptually \"printed\" on " +
"a sheet of material. In Flutter\'s material library, that " +
"a sheet of material. In UIWidgets\'s material library, that " +
"material is represented by the Material widget. It is the " +
"Material widget that renders ink splashes, for instance. " +
"Because of this, many material library widgets require that " +

if (ancestors.isNotEmpty()) {
message += "The ancestors of this widget were:";
foreach (Widget ancestor in ancestors) {
message += "\n $ancestor";
message += "\n " + ancestor;
}
else {
} else {
message += "This widget is the root of the tree, so it has no " +
"ancestors, let alone a \"Material\" ancestor.";
}

return true;
});
return true;
}
public static bool debugCheckHasMaterialLocalizations(BuildContext context) {
D.assert(() => {
if (Localizations.of<MaterialLocalizations>(context, typeof(MaterialLocalizations)) == null) {
StringBuilder message = new StringBuilder();
message.AppendLine("No MaterialLocalizations found.");
message.AppendLine(
context.widget.GetType() + " widgets require MaterialLocalizations " +
"to be provided by a Localizations widget ancestor.");
message.AppendLine(
"Localizations are used to generate many different messages, labels," +
"and abbreviations which are used by the material library. ");
message.AppendLine(
"To introduce a MaterialLocalizations, either use a " +
" MaterialApp at the root of your application to include them " +
"automatically, or add a Localization widget with a " +
"MaterialLocalizations delegate.");
message.AppendLine(
"The specific widget that could not find a MaterialLocalizations ancestor was:"
);
message.AppendLine(" " + context.widget);
List<Widget> ancestors = new List<Widget>();
context.visitAncestorElements((Element element) => {
ancestors.Add(element.widget);
return true;
});
if (ancestors.isNotEmpty()) {
message.Append("The ancestors of this widget were:");
foreach (Widget ancestor in ancestors) {
message.Append("\n " + ancestor);
}
} else {
message.AppendLine(
"This widget is the root of the tree, so it has no " +
"ancestors, let alone a \"Localizations\" ancestor."
);
}
throw new UIWidgetsError(message.ToString());
}
return true;
});
return true;

5
Runtime/material/dialog.cs


public readonly ShapeBorder shape;
public override Widget build(BuildContext context) {
// D.assert(debugCheckHasMaterialLocalizations(context));
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
List<Widget> body = new List<Widget>();

bool barrierDismissible = true,
WidgetBuilder builder = null
) {
// D.assert(debugCheckHasMaterialLocalizations(context));
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
return widgets.DialogUtils.showGeneralDialog(
context: context,

);
},
barrierDismissible: barrierDismissible,
// barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black54,
transitionDuration: new TimeSpan(0, 0, 0, 0, 150),
transitionBuilder: _buildMaterialDialogTransitions

2
Runtime/material/drawer_header.cs


public override Widget build(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
ThemeData theme = Theme.of(context);
float statusBarHeight = MediaQuery.of(context).padding.top;
return new Container(

2
Runtime/material/expand_icon.cs


public override Widget build(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
ThemeData theme = Theme.of(context);
return new IconButton(
padding: this.widget.padding,

2
Runtime/material/icon_button.cs


public readonly string tooltip;
public override Widget build(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
Color currentColor;
if (this.onPressed != null) {
currentColor = this.color;

2
Runtime/material/ink_decoration.cs


}
public override Widget build(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
Widget result = new LayoutBuilder(
builder: this._build
);

2
Runtime/material/ink_well.cs


public virtual bool debugCheckContext(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
return true;
}

2
Runtime/material/list_tile.cs


}
public override Widget build(BuildContext context) {
D.assert(MaterialDebug.debugCheckHasMaterial(context));
D.assert(MaterialD.debugCheckHasMaterial(context));
ThemeData theme = Theme.of(context);
ListTileTheme tileTheme = ListTileTheme.of(context);

4
Runtime/material/page.cs


get { return null; }
}
public override string barrierLabel {
get { return null; }
}
public override bool canTransitionFrom(TransitionRoute previousRoute) {
return previousRoute is MaterialPageRoute;
}

20
Runtime/material/theme_data.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
static class ThemeDataUtils {

IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
ColorScheme colorScheme = null,

: new IconThemeData(color: Colors.black));
iconTheme = iconTheme ??
(isDark ? new IconThemeData(color: Colors.white) : new IconThemeData(color: Colors.black87));
platform = platform ?? Application.platform;
typography = typography ?? new Typography();
TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
textTheme = defaultTextTheme.merge(textTheme);

this.iconTheme = iconTheme;
this.primaryIconTheme = primaryIconTheme;
this.accentIconTheme = accentIconTheme;
this.platform = platform;
this.materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
this.pageTransitionsTheme = pageTransitionsTheme;
this.colorScheme = colorScheme;

IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
ColorScheme colorScheme = null,

D.assert(iconTheme != null);
D.assert(primaryIconTheme != null);
D.assert(accentIconTheme != null);
D.assert(platform != null);
D.assert(materialTapTargetSize != null);
D.assert(pageTransitionsTheme != null);
D.assert(colorScheme != null);

iconTheme: iconTheme,
primaryIconTheme: primaryIconTheme,
accentIconTheme: accentIconTheme,
platform: platform,
materialTapTargetSize: materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme,
colorScheme: colorScheme,

public readonly IconThemeData accentIconTheme;
public readonly RuntimePlatform platform;
public readonly MaterialTapTargetSize materialTapTargetSize;
public readonly PageTransitionsTheme pageTransitionsTheme;

IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
ColorScheme colorScheme = null,

iconTheme: iconTheme ?? this.iconTheme,
primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
accentIconTheme: accentIconTheme ?? this.accentIconTheme,
platform: platform ?? this.platform,
materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,
colorScheme: colorScheme ?? this.colorScheme,

}
public static Brightness estimateBrightnessForColor(Color color) {
float relativeLuminance = color.computeLuminance();

iconTheme: IconThemeData.lerp(a.iconTheme, b.iconTheme, t),
primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
platform: t < 0.5 ? a.platform : b.platform,
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
pageTransitionsTheme: t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),

other.iconTheme == this.iconTheme &&
other.primaryIconTheme == this.primaryIconTheme &&
other.accentIconTheme == this.accentIconTheme &&
other.platform == this.platform &&
other.materialTapTargetSize == this.materialTapTargetSize &&
other.pageTransitionsTheme == this.pageTransitionsTheme &&
other.colorScheme == this.colorScheme &&

hashCode = (hashCode * 397) ^ this.iconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.primaryIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.accentIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.platform.GetHashCode();
hashCode = (hashCode * 397) ^ this.materialTapTargetSize.GetHashCode();
hashCode = (hashCode * 397) ^ this.pageTransitionsTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
ThemeData defaultData = fallback();
properties.add(new EnumProperty<RuntimePlatform>("platform", this.platform,
defaultValue: Application.platform));
properties.add(new EnumProperty<Brightness>("brightness", this.brightness,
defaultValue: defaultData.brightness));
properties.add(new DiagnosticsProperty<Color>("primaryColor", this.primaryColor,

1
Runtime/painting/image_resolution.cs


public readonly string assetName;
public readonly AssetBundle bundle;
protected override
IPromise<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) {
AssetImageConfiguration assetConfig = new AssetImageConfiguration(configuration, this.assetName);

4
Runtime/ui/geometry.cs


return value;
}
public static int abs(this int value) {
return Mathf.Abs(value);
}
public static float abs(this float value) {
return Mathf.Abs(value);
}

67
Runtime/widgets/basic.cs


}
}
public class Baseline : SingleChildRenderObjectWidget {
public Baseline(
Key key = null,
float? baseline = null,
TextBaseline? baselineType = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(baseline != null);
D.assert(baselineType != null);
this.baseline = baseline.Value;
this.baselineType = baselineType.Value;
}
public readonly float baseline;
public readonly TextBaseline baselineType;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderBaseline(baseline: this.baseline, baselineType: this.baselineType);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObjectRaw) {
RenderBaseline renderObject = (RenderBaseline) renderObjectRaw;
renderObject.baseline = this.baseline;
renderObject.baselineType = this.baselineType;
}
}
public class ListBody : MultiChildRenderObjectWidget {
public ListBody(
Key key = null,

properties.add(new DiagnosticsProperty<object>("metaData", this.metaData));
}
}
public class KeyedSubtree : StatelessWidget {
public KeyedSubtree(
Key key,
Widget child = null
) : base(key: key) {
D.assert(child != null);
this.child = child;
}
public static KeyedSubtree wrap(Widget child, int childIndex) {
Key key = child.key != null ? (Key) new ValueKey<Key>(child.key) : new ValueKey<int>(childIndex);
return new KeyedSubtree(key: key, child: child);
}
public readonly Widget child;
public static List<Widget> ensureUniqueKeysForList(IEnumerable<Widget> items, int baseIndex = 0) {
if (items == null) {
return null;
}
List<Widget> itemsWithUniqueKeys = new List<Widget>();
int itemIndex = baseIndex;
foreach (Widget item in items) {
itemsWithUniqueKeys.Add(KeyedSubtree.wrap(item, itemIndex));
itemIndex += 1;
}
D.assert(!WidgetsD.debugItemsHaveDuplicateKeys(itemsWithUniqueKeys));
return itemsWithUniqueKeys;
}
public override Widget build(BuildContext context) {
return this.child;
}
}
public class Builder : StatelessWidget {
public Builder(

30
Runtime/widgets/debug.cs


return false;
}
public static bool debugItemsHaveDuplicateKeys(IEnumerable<Widget> items) {
D.assert(() => {
Key nonUniqueKey = _firstNonUniqueKey(items);
if (nonUniqueKey != null) {
throw new UIWidgetsError($"Duplicate key found: {nonUniqueKey}.");
}
return true;
});
return false;
}
public static void debugWidgetBuilderValue(Widget widget, Widget built) {
D.assert(() => {

return true;
});
}
public static bool debugCheckHasMediaQuery(BuildContext context) {
D.assert(() => {
if (!(context.widget is MediaQuery) && context.ancestorWidgetOfExactType(typeof(MediaQuery)) == null) {
Element element = (Element) context;
throw new UIWidgetsError(
"No MediaQuery widget found.\n" +
context.widget.GetType() + " widgets require a MediaQuery widget ancestor.\n" +
"The specific widget that could not find a MediaQuery ancestor was:\n" +
" " + context.widget + "\n" +
"The ownership chain for the affected widget is:\n" +
" " + element.debugGetCreatorChain(10) + "\n" +
"Typically, the MediaQuery widget is introduced by the MaterialApp or " +
"WidgetsApp widget at the top of your application widget tree."
);
}
return true;
});
return true;
}
public static bool debugCheckHasDirectionality(BuildContext context) {

4
Runtime/widgets/pages.cs


bool opaque = true,
bool barrierDismissible = false,
Color barrierColor = null,
string barrierLabel = null,
bool maintainState = true
) : base(settings) {
D.assert(pageBuilder != null);

this.transitionDuration = transitionDuration ?? TimeSpan.FromMilliseconds(300);
this.barrierColor = barrierColor;
this.maintainState = maintainState;
this.barrierLabel = barrierLabel;
this.barrierDismissible = barrierDismissible;
}

public override bool barrierDismissible { get; }
public override Color barrierColor { get; }
public override string barrierLabel { get; }
public override bool maintainState { get; }

11
Runtime/widgets/routes.cs


public virtual bool barrierDismissible { get; }
public virtual string barrierLabel { get; }
public virtual bool maintainState { get; }

class _DialogRoute : PopupRoute {
internal _DialogRoute(RoutePageBuilder pageBuilder = null, bool barrierDismissible = true,
string barrierLabel = null,
Color barrierColor = null,
TimeSpan? transitionDuration = null,
RouteTransitionsBuilder transitionBuilder = null,

this.barrierLabel = barrierLabel;
this.barrierColor = barrierColor ?? new Color(0x80000000);
this.transitionDuration = transitionDuration ?? TimeSpan.FromMilliseconds(200);
this._transitionBuilder = transitionBuilder;

public override bool barrierDismissible { get; }
public override string barrierLabel { get; }
public override Color barrierColor { get; }

BuildContext context = null,
RoutePageBuilder pageBuilder = null,
bool barrierDismissible = false,
string barrierLabel = null,
D.assert(!barrierDismissible || barrierLabel != null);
barrierLabel: barrierLabel,
barrierColor: barrierColor,
transitionDuration: transitionDuration,
transitionBuilder: transitionBuilder

1
Samples/UIWidgetSample/NavigationSample.cs


return builder(buildContext);
},
barrierDismissible: barrierDismissible,
barrierLabel: "",
barrierColor: new Color(0x8A000000),
transitionDuration: TimeSpan.FromMilliseconds(150),
transitionBuilder: _buildMaterialDialogTransitions

21
Samples/UIWidgetsGallery/gallery/app.cs


Timer _timeDilationTimer;
Dictionary<string, WidgetBuilder> _buildRoutes() {
return GalleryDemo.kAllGalleryDemos.ToDictionary(
return DemoUtils.kAllGalleryDemos.ToDictionary(
(demo) => $"{demo.routeName}",
(demo) => demo.buildRoute);
}

}
public override Widget build(BuildContext context) {
// Widget home = new GalleryHome(
// testMode: this.widget.testMode,
// optionsPage: new GalleryOptionsPage(
// options: this._options,
// onOptionsChanged: _handleOptionsChanged,
// onSendFeedback: this.widget.onSendFeedback ?? () => { Application.OpenURL("https://github.com/UnityTech/UIWidgets/issues"); }
// )
// );
Widget home = new GalleryHome(
testMode: this.widget.testMode,
optionsPage: new GalleryOptionsPage(
options: this._options,
onOptionsChanged: this._handleOptionsChanged,
onSendFeedback: this.widget.onSendFeedback ?? (() => {
Application.OpenURL("https://github.com/UnityTech/UIWidgets/issues");
})
)
);
Widget home = null;
if (this.widget.updateUrlFetcher != null) {
home = new Updater(
updateUrlFetcher: this.widget.updateUrlFetcher,

17
Samples/UIWidgetsGallery/gallery/demos.cs


namespace UIWidgetsGallery.gallery {
public class GalleryDemoCategory : IEquatable<GalleryDemoCategory> {
GalleryDemoCategory(string name = null, IconData icon = null) {
public GalleryDemoCategory(string name = null, IconData icon = null) {
D.assert(name != null);
D.assert(icon != null);

public override string ToString() {
return $"{this.GetType()}({this.name})";
}
}
public static readonly GalleryDemoCategory _kDemos = new GalleryDemoCategory(
public static partial class DemoUtils {
internal static readonly GalleryDemoCategory _kDemos = new GalleryDemoCategory(
public static readonly GalleryDemoCategory _kStyle = new GalleryDemoCategory(
internal static readonly GalleryDemoCategory _kStyle = new GalleryDemoCategory(
public static readonly GalleryDemoCategory _kMaterialComponents = new GalleryDemoCategory(
internal static readonly GalleryDemoCategory _kMaterialComponents = new GalleryDemoCategory(
public static readonly GalleryDemoCategory _kCupertinoComponents = new GalleryDemoCategory(
internal static readonly GalleryDemoCategory _kCupertinoComponents = new GalleryDemoCategory(
public static readonly GalleryDemoCategory _kMedia = new GalleryDemoCategory(
internal static readonly GalleryDemoCategory _kMedia = new GalleryDemoCategory(
name: "Media",
icon: GalleryIcons.drive_video
);

return $"{this.GetType()}({this.title} {this.routeName})";
}
}
public static partial class DemoUtils {
static List<GalleryDemo> _buildGalleryDemos() {
List<GalleryDemo> galleryDemos = new List<GalleryDemo> {
// // Demos

365
Samples/UIWidgetsGallery/gallery/options.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Color = Unity.UIWidgets.ui.Color;
namespace UIWidgetsGallery.gallery {
public class GalleryOptions : IEquatable<GalleryOptions> {

public override string ToString() {
return $"{this.GetType()}({this.theme})";
}
}
class _OptionsItem : StatelessWidget {
const float _kItemHeight = 48.0f;
static readonly EdgeInsets _kItemPadding = EdgeInsets.only(left: 56.0f);
public _OptionsItem(Key key = null, Widget child = null) : base(key: key) {
this.child = child;
}
public readonly Widget child;
public override Widget build(BuildContext context) {
float textScaleFactor = MediaQuery.textScaleFactorOf(context);
return new Container(
constraints: new BoxConstraints(minHeight: _kItemHeight * textScaleFactor),
padding: _kItemPadding,
alignment: Alignment.centerLeft,
child: new DefaultTextStyle(
style: DefaultTextStyle.of(context).style,
maxLines: 2,
overflow: TextOverflow.fade,
child: new IconTheme(
data: Theme.of(context).primaryIconTheme,
child: this.child
)
)
);
}
}
class _BooleanItem : StatelessWidget {
public _BooleanItem(string title, bool value, ValueChanged<bool?> onChanged, Key switchKey = null) {
this.title = title;
this.value = value;
this.onChanged = onChanged;
this.switchKey = switchKey;
}
public readonly string title;
public readonly bool value;
public readonly ValueChanged<bool?> onChanged;
public readonly Key switchKey;
public override Widget build(BuildContext context) {
bool isDark = Theme.of(context).brightness == Brightness.dark;
return new _OptionsItem(
child: new Row(
children: new List<Widget> {
new Expanded(child: new Text(this.title)),
new Switch(
key: this.switchKey,
value: this.value,
onChanged: this.onChanged,
activeColor: new Color(0xFF39CEFD),
activeTrackColor: isDark ? Colors.white30 : Colors.black26
)
}
)
);
}
}
class _ActionItem : StatelessWidget {
public _ActionItem(string text, VoidCallback onTap) {
this.text = text;
this.onTap = onTap;
}
public readonly string text;
public readonly VoidCallback onTap;
public override Widget build(BuildContext context) {
return new _OptionsItem(
child: new _FlatButton(
onPressed: this.onTap,
child: new Text(this.text)
)
);
}
}
class _FlatButton : StatelessWidget {
public _FlatButton(Key key = null, VoidCallback onPressed = null, Widget child = null) : base(key: key) {
this.onPressed = onPressed;
this.child = child;
}
public readonly VoidCallback onPressed;
public readonly Widget child;
public override Widget build(BuildContext context) {
return new FlatButton(
padding: EdgeInsets.zero,
onPressed: this.onPressed,
child: new DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.subhead,
child: this.child
)
);
}
}
class _Heading : StatelessWidget {
public _Heading(string text) {
this.text = text;
}
public readonly string text;
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
return new _OptionsItem(
child: new DefaultTextStyle(
style: theme.textTheme.body1.copyWith(
fontFamily: "GoogleSans",
color: theme.accentColor
),
child: new Text(this.text)
)
);
}
}
class _ThemeItem : StatelessWidget {
public _ThemeItem(GalleryOptions options, ValueChanged<GalleryOptions> onOptionsChanged) {
this.options = options;
this.onOptionsChanged = onOptionsChanged;
}
public readonly GalleryOptions options;
public readonly ValueChanged<GalleryOptions> onOptionsChanged;
public override Widget build(BuildContext context) {
return new _BooleanItem(
"Dark Theme",
this.options.theme == GalleryTheme.kDarkGalleryTheme,
(bool? value) => {
this.onOptionsChanged(
this.options.copyWith(
theme: value == true ? GalleryTheme.kDarkGalleryTheme : GalleryTheme.kLightGalleryTheme
)
);
},
switchKey: Key.key("dark_theme")
);
}
}
class _TextScaleFactorItem : StatelessWidget {
public _TextScaleFactorItem(GalleryOptions options, ValueChanged<GalleryOptions> onOptionsChanged) {
this.options = options;
this.onOptionsChanged = this.onOptionsChanged;
}
public readonly GalleryOptions options;
public readonly ValueChanged<GalleryOptions> onOptionsChanged;
public override Widget build(BuildContext context) {
return new _OptionsItem(
child: new Row(
children: new List<Widget> {
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget> {
new Text("Text size"),
new Text(
this.options.textScaleFactor.label,
style: Theme.of(context).primaryTextTheme.body1
),
}
)
),
new PopupMenuButton<GalleryTextScaleValue>(
padding: EdgeInsets.only(right: 16.0f),
icon: new Icon(Icons.arrow_drop_down),
itemBuilder: _ => {
return GalleryTextScaleValue.kAllGalleryTextScaleValues.Select(scaleValue =>
(PopupMenuEntry<GalleryTextScaleValue>) new PopupMenuItem<GalleryTextScaleValue>(
value: scaleValue,
child: new Text(scaleValue.label)
)).ToList();
},
onSelected: scaleValue => {
this.onOptionsChanged(
this.options.copyWith(textScaleFactor: scaleValue)
);
}
),
}
)
);
}
}
class _TimeDilationItem : StatelessWidget {
public _TimeDilationItem(GalleryOptions options, ValueChanged<GalleryOptions> onOptionsChanged) {
this.options = options;
this.onOptionsChanged = onOptionsChanged;
}
public readonly GalleryOptions options;
public readonly ValueChanged<GalleryOptions> onOptionsChanged;
public override Widget build(BuildContext context) {
return new _BooleanItem(
"Slow motion",
this.options.timeDilation != 1.0f,
(bool? value) => {
this.onOptionsChanged(
this.options.copyWith(
timeDilation: value == true ? 20.0f : 1.0f
)
);
},
switchKey: Key.key("slow_motion")
);
}
}
class _PlatformItem : StatelessWidget {
public _PlatformItem(GalleryOptions options, ValueChanged<GalleryOptions> onOptionsChanged) {
this.options = options;
this.onOptionsChanged = onOptionsChanged;
}
public readonly GalleryOptions options;
public readonly ValueChanged<GalleryOptions> onOptionsChanged;
string _platformLabel(RuntimePlatform platform) {
return platform.ToString();
}
public override Widget build(BuildContext context) {
return new _OptionsItem(
child: new Row(
children: new List<Widget> {
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget> {
new Text("Platform mechanics"),
new Text(
this._platformLabel(this.options.platform),
style: Theme.of(context).primaryTextTheme.body1
),
}
)
),
new PopupMenuButton<RuntimePlatform>(
padding: EdgeInsets.only(right: 16.0f),
icon: new Icon(Icons.arrow_drop_down),
itemBuilder: _ => {
var values = Enum.GetValues(typeof(RuntimePlatform)).Cast<RuntimePlatform>();
return values.Select(platform =>
(PopupMenuEntry<RuntimePlatform>) new PopupMenuItem<RuntimePlatform>(
value: platform,
child: new Text(this._platformLabel(platform))
)).ToList();
},
onSelected: platform => {
this.onOptionsChanged(
this.options.copyWith(platform: platform)
);
}
),
}
)
);
}
}
public class GalleryOptionsPage : StatelessWidget {
public GalleryOptionsPage(
Key key = null,
GalleryOptions options = null,
ValueChanged<GalleryOptions> onOptionsChanged = null,
VoidCallback onSendFeedback = null
) : base(key: key) {
this.options = options;
this.onOptionsChanged = onOptionsChanged;
this.onSendFeedback = onSendFeedback;
}
public readonly GalleryOptions options;
public readonly ValueChanged<GalleryOptions> onOptionsChanged;
public readonly VoidCallback onSendFeedback;
List<Widget> _enabledDiagnosticItems() {
List<Widget> items = new List<Widget> {
new Divider(),
new _Heading("Diagnostics"),
};
items.Add(
new _BooleanItem(
"Highlight offscreen layers",
this.options.showOffscreenLayersCheckerboard,
(bool? value) => {
this.onOptionsChanged(this.options.copyWith(showOffscreenLayersCheckerboard: value));
}
)
);
items.Add(
new _BooleanItem(
"Highlight raster cache images",
this.options.showRasterCacheImagesCheckerboard,
(bool? value) => {
this.onOptionsChanged(this.options.copyWith(showRasterCacheImagesCheckerboard: value));
}
)
);
items.Add(
new _BooleanItem(
"Show performance overlay",
this.options.showPerformanceOverlay,
(bool? value) => { this.onOptionsChanged(this.options.copyWith(showPerformanceOverlay: value)); }
)
);
return items;
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
var children = new List<Widget> {
new _Heading("Display"),
new _ThemeItem(this.options, this.onOptionsChanged),
new _TextScaleFactorItem(this.options, this.onOptionsChanged),
new _TimeDilationItem(this.options, this.onOptionsChanged),
new Divider(),
new _Heading("Platform mechanics"),
new _PlatformItem(this.options, this.onOptionsChanged)
};
children.AddRange(this._enabledDiagnosticItems());
children.AddRange(new List<Widget> {
new Divider(),
new _Heading("UIWidgets Gallery"),
new _ActionItem("About UIWidgets Gallery", () => {
/* showGalleryAboutDialog(context); */
}),
new _ActionItem("Send feedback", this.onSendFeedback),
});
return new DefaultTextStyle(
style: theme.primaryTextTheme.subhead,
child: new ListView(
padding: EdgeInsets.only(bottom: 124.0f),
children: children
));
}
}
}

390
Runtime/material/material_localizations.cs


using System;
using System.Collections.Generic;
using System.Text;
using RSG;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public abstract class MaterialLocalizations {
public abstract string openAppDrawerTooltip { get; }
public abstract string backButtonTooltip { get; }
public abstract string closeButtonTooltip { get; }
public abstract string deleteButtonTooltip { get; }
public abstract string nextMonthTooltip { get; }
public abstract string previousMonthTooltip { get; }
public abstract string nextPageTooltip { get; }
public abstract string previousPageTooltip { get; }
public abstract string showMenuTooltip { get; }
public abstract string aboutListTileTitle(string applicationName);
public abstract string licensesPageTitle { get; }
public abstract string pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate);
public abstract string rowsPerPageTitle { get; }
public abstract string tabLabel(int tabIndex, int tabCount);
public abstract string selectedRowCountTitle(int selectedRowCount);
public abstract string cancelButtonLabel { get; }
public abstract string closeButtonLabel { get; }
public abstract string continueButtonLabel { get; }
public abstract string copyButtonLabel { get; }
public abstract string cutButtonLabel { get; }
public abstract string okButtonLabel { get; }
public abstract string pasteButtonLabel { get; }
public abstract string selectAllButtonLabel { get; }
public abstract string viewLicensesButtonLabel { get; }
public abstract string anteMeridiemAbbreviation { get; }
public abstract string postMeridiemAbbreviation { get; }
public abstract string searchFieldLabel { get; }
public abstract TimeOfDayFormat timeOfDayFormat(bool alwaysUse24HourFormat = false);
public abstract ScriptCategory scriptCategory { get; }
public abstract string formatDecimal(int number);
public abstract string formatHour(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false);
public abstract string formatMinute(TimeOfDay timeOfDay);
public abstract string formatTimeOfDay(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false);
public abstract string formatYear(DateTime date);
public abstract string formatMediumDate(DateTime date);
public abstract string formatFullDate(DateTime date);
public abstract string formatMonthYear(DateTime date);
public abstract List<string> narrowWeekdays { get; }
public abstract int firstDayOfWeekIndex { get; }
public static MaterialLocalizations of(BuildContext context) {
return Localizations.of<MaterialLocalizations>(context, typeof(MaterialLocalizations));
}
}
class _MaterialLocalizationsDelegate : LocalizationsDelegate<MaterialLocalizations> {
public _MaterialLocalizationsDelegate() {
}
public override bool isSupported(Locale locale) {
return locale.languageCode == "en";
}
public override IPromise<object> load(Locale locale) {
return DefaultMaterialLocalizations.load(locale);
}
public override bool shouldReload(LocalizationsDelegate old) {
return false;
}
public override string ToString() {
return "DefaultMaterialLocalizations.delegate(en_US)";
}
}
public class DefaultMaterialLocalizations : MaterialLocalizations {
public DefaultMaterialLocalizations() {
}
static readonly List<string> _shortWeekdays = new List<string>() {
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
};
static readonly List<String> _weekdays = new List<string>() {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
};
static readonly List<String> _narrowWeekdays = new List<string>() {
"S",
"M",
"T",
"W",
"T",
"F",
"S",
};
static readonly List<String> _shortMonths = new List<string>() {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
};
static readonly List<String> _months = new List<string>() {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
};
public override string formatHour(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false) {
TimeOfDayFormat format = this.timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat);
switch (format) {
case TimeOfDayFormat.h_colon_mm_space_a:
return this.formatDecimal(timeOfDay.hourOfPeriod == 0 ? 12 : timeOfDay.hourOfPeriod);
case TimeOfDayFormat.HH_colon_mm:
return this._formatTwoDigitZeroPad(timeOfDay.hour);
default:
throw new AssertionError($"runtimeType does not support {format}.");
}
}
string _formatTwoDigitZeroPad(int number) {
D.assert(0 <= number && number < 100);
if (number < 10) {
return "0" + number;
}
return number.ToString();
}
public override string formatMinute(TimeOfDay timeOfDay) {
int minute = timeOfDay.minute;
return minute < 10 ? "0" + minute : minute.ToString();
}
public override string formatYear(DateTime date) {
return date.Year.ToString();
}
public override string formatMediumDate(DateTime date) {
string day = _shortWeekdays[((int) date.DayOfWeek + 6) % 7];
string month = _shortMonths[date.Month - 1];
return $"{day}, {month} ${date.Day}";
}
public override string formatFullDate(DateTime date) {
string month = _months[date.Month - 1];
return $"{_weekdays[((int) date.DayOfWeek + 6) % 7]}, {month} {date.Day}, {date.Year}";
}
public override string formatMonthYear(DateTime date) {
string year = this.formatYear(date);
string month = _months[date.Month - 1];
return $"{month} {year}";
}
public override List<string> narrowWeekdays {
get { return _narrowWeekdays; }
}
public override int firstDayOfWeekIndex {
get { return 0; }
}
string _formatDayPeriod(TimeOfDay timeOfDay) {
switch (timeOfDay.period) {
case DayPeriod.am:
return this.anteMeridiemAbbreviation;
case DayPeriod.pm:
return this.postMeridiemAbbreviation;
}
return null;
}
public override string formatDecimal(int number) {
if (number > -1000 && number < 1000) {
return number.ToString();
}
string digits = number.abs().ToString();
StringBuilder result = new StringBuilder(number < 0 ? "-" : "");
int maxDigitIndex = digits.Length - 1;
for (int i = 0; i <= maxDigitIndex; i += 1) {
result.Append(digits[i]);
if (i < maxDigitIndex && (maxDigitIndex - i) % 3 == 0) {
result.Append(',');
}
}
return result.ToString();
}
public override string formatTimeOfDay(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false) {
StringBuilder buffer = new StringBuilder();
buffer.Append(this.formatHour(timeOfDay, alwaysUse24HourFormat: alwaysUse24HourFormat));
buffer.Append(":");
buffer.Append(this.formatMinute(timeOfDay));
if (alwaysUse24HourFormat) {
return buffer.ToString();
}
buffer.Append(" ");
buffer.Append(this._formatDayPeriod(timeOfDay));
return buffer.ToString();
}
public override string openAppDrawerTooltip {
get { return "Open navigation menu"; }
}
public override string backButtonTooltip {
get { return "Back"; }
}
public override string closeButtonTooltip {
get { return "Close"; }
}
public override string deleteButtonTooltip {
get { return "Delete"; }
}
public override string nextMonthTooltip {
get { return "Next month"; }
}
public override string previousMonthTooltip {
get { return "Previous month"; }
}
public override string nextPageTooltip {
get { return "Next page"; }
}
public override string previousPageTooltip {
get { return "Previous page"; }
}
public override string showMenuTooltip {
get { return "Show menu"; }
}
public override string searchFieldLabel {
get { return "Search"; }
}
public override string aboutListTileTitle(string applicationName) {
return "About " + applicationName;
}
public override string licensesPageTitle {
get { return "Licenses"; }
}
public override string pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate) {
return rowCountIsApproximate
? $"{firstRow}–{lastRow} of about {rowCount}"
: $"{firstRow}–{lastRow} of {rowCount}";
}
public override string rowsPerPageTitle {
get { return "Rows per page:"; }
}
public override string tabLabel(int tabIndex, int tabCount) {
D.assert(tabIndex >= 1);
D.assert(tabCount >= 1);
return $"Tab {tabIndex} of {tabCount}";
}
public override string selectedRowCountTitle(int selectedRowCount) {
switch (selectedRowCount) {
case 0:
return "No items selected";
case 1:
return "1 item selected";
default:
return selectedRowCount + " items selected";
}
}
public override string cancelButtonLabel {
get { return "CANCEL"; }
}
public override string closeButtonLabel {
get { return "CLOSE"; }
}
public override string continueButtonLabel {
get { return "CONTINUE"; }
}
public override string copyButtonLabel {
get { return "COPY"; }
}
public override string cutButtonLabel {
get { return "CUT"; }
}
public override string okButtonLabel {
get { return "OK"; }
}
public override string pasteButtonLabel {
get { return "PASTE"; }
}
public override string selectAllButtonLabel {
get { return "SELECT ALL"; }
}
public override string viewLicensesButtonLabel {
get { return "VIEW LICENSES"; }
}
public override string anteMeridiemAbbreviation {
get { return "AM"; }
}
public override string postMeridiemAbbreviation {
get { return "PM"; }
}
public override ScriptCategory scriptCategory {
get { return ScriptCategory.englishLike; }
}
public override TimeOfDayFormat timeOfDayFormat(bool alwaysUse24HourFormat = false) {
return alwaysUse24HourFormat
? TimeOfDayFormat.HH_colon_mm
: TimeOfDayFormat.h_colon_mm_space_a;
}
public static IPromise<object> load(Locale locale) {
return Promise<object>.Resolved(new DefaultMaterialLocalizations());
}
public static readonly LocalizationsDelegate<MaterialLocalizations> del = new _MaterialLocalizationsDelegate();
}
}

11
Runtime/material/material_localizations.cs.meta


fileFormatVersion: 2
guid: d140c1ef287754af7adf006964153c07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

608
Runtime/material/popup_menu.cs


using System;
using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public static partial class PopupMenuUtils {
internal static readonly TimeSpan _kMenuDuration = new TimeSpan(0, 0, 0, 0, 300);
internal const float _kBaselineOffsetFromBottom = 20.0f;
internal const float _kMenuCloseIntervalEnd = 2.0f / 3.0f;
internal const float _kMenuHorizontalPadding = 16.0f;
internal const float _kMenuItemHeight = 48.0f;
internal const float _kMenuDividerHeight = 16.0f;
internal const float _kMenuMaxWidth = 5.0f * _kMenuWidthStep;
internal const float _kMenuMinWidth = 2.0f * _kMenuWidthStep;
internal const float _kMenuVerticalPadding = 8.0f;
internal const float _kMenuWidthStep = 56.0f;
internal const float _kMenuScreenPadding = 8.0f;
}
public abstract class PopupMenuEntry<T> : StatefulWidget {
protected PopupMenuEntry(Key key = null) : base(key: key) {
}
public abstract float height { get; }
public abstract bool represents(T value);
}
public class PopupMenuDivider : PopupMenuEntry<object> {
public PopupMenuDivider(Key key = null, float height = PopupMenuUtils._kMenuDividerHeight) : base(key: key) {
this._height = height;
}
readonly float _height;
public override float height {
get { return this._height; }
}
public override bool represents(object value) {
return false;
}
public override State createState() {
return new _PopupMenuDividerState();
}
}
class _PopupMenuDividerState : State<PopupMenuDivider> {
public override Widget build(BuildContext context) {
return new Divider(height: this.widget.height);
}
}
public class PopupMenuItem<T> : PopupMenuEntry<T> {
public PopupMenuItem(
Key key = null,
T value = default,
bool enabled = true,
float height = PopupMenuUtils._kMenuItemHeight,
Widget child = null
) : base(key: key) {
this.value = value;
this.enabled = enabled;
this._height = height;
this.child = child;
}
public readonly T value;
public readonly bool enabled;
readonly float _height;
public override float height {
get { return this._height; }
}
public readonly Widget child;
public override bool represents(T value) {
return Equals(value, this.value);
}
public override State createState() {
return new PopupMenuItemState<T, PopupMenuItem<T>>();
}
}
public class PopupMenuItemState<T, W> : State<W> where W : PopupMenuItem<T> {
protected virtual Widget buildChild() {
return this.widget.child;
}
protected virtual void handleTap() {
Navigator.pop(this.context, this.widget.value);
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextStyle style = theme.textTheme.subhead;
if (!this.widget.enabled) {
style = style.copyWith(color: theme.disabledColor);
}
Widget item = new AnimatedDefaultTextStyle(
style: style,
duration: Constants.kThemeChangeDuration,
child: new Baseline(
baseline: this.widget.height - PopupMenuUtils._kBaselineOffsetFromBottom,
baselineType: style.textBaseline,
child: this.buildChild()
)
);
if (!this.widget.enabled) {
bool isDark = theme.brightness == Brightness.dark;
item = IconTheme.merge(
data: new IconThemeData(opacity: isDark ? 0.5f : 0.38f),
child: item
);
}
return new InkWell(
onTap: this.widget.enabled ? this.handleTap : (GestureTapCallback) null,
child: new Container(
height: this.widget.height,
padding: EdgeInsets.symmetric(horizontal: PopupMenuUtils._kMenuHorizontalPadding),
child: item
)
);
}
}
public class PopupMenuItemSingleTickerProviderState<T, W> : SingleTickerProviderStateMixin<W>
where W : PopupMenuItem<T> {
protected virtual Widget buildChild() {
return this.widget.child;
}
protected virtual void handleTap() {
Navigator.pop(this.context, this.widget.value);
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextStyle style = theme.textTheme.subhead;
if (!this.widget.enabled) {
style = style.copyWith(color: theme.disabledColor);
}
Widget item = new AnimatedDefaultTextStyle(
style: style,
duration: Constants.kThemeChangeDuration,
child: new Baseline(
baseline: this.widget.height - PopupMenuUtils._kBaselineOffsetFromBottom,
baselineType: style.textBaseline,
child: this.buildChild()
)
);
if (!this.widget.enabled) {
bool isDark = theme.brightness == Brightness.dark;
item = IconTheme.merge(
data: new IconThemeData(opacity: isDark ? 0.5f : 0.38f),
child: item
);
}
return new InkWell(
onTap: this.widget.enabled ? this.handleTap : (GestureTapCallback) null,
child: new Container(
height: this.widget.height,
padding: EdgeInsets.symmetric(horizontal: PopupMenuUtils._kMenuHorizontalPadding),
child: item
)
);
}
}
class CheckedPopupMenuItem<T> : PopupMenuItem<T> {
public CheckedPopupMenuItem(
Key key = null,
T value = default,
bool isChecked = false,
bool enabled = true,
Widget child = null
) : base(
key: key,
value: value,
enabled: enabled,
child: child
) {
this.isChecked = isChecked;
}
public readonly bool isChecked;
public override State createState() {
return new _CheckedPopupMenuItemState<T>();
}
}
class _CheckedPopupMenuItemState<T> : PopupMenuItemSingleTickerProviderState<T, CheckedPopupMenuItem<T>> {
static readonly TimeSpan _fadeDuration = new TimeSpan(0, 0, 0, 0, 150);
AnimationController _controller;
Animation<float> _opacity {
get { return this._controller.view; }
}
public override void initState() {
base.initState();
this._controller = new AnimationController(duration: _fadeDuration, vsync: this);
this._controller.setValue(this.widget.isChecked ? 1.0f : 0.0f);
this._controller.addListener(() => this.setState(() => {
/* animation changed */
}));
}
protected override void handleTap() {
if (this.widget.isChecked) {
this._controller.reverse();
} else {
this._controller.forward();
}
base.handleTap();
}
protected override Widget buildChild() {
return new ListTile(
enabled: this.widget.enabled,
leading: new FadeTransition(
opacity: this._opacity,
child: new Icon(this._controller.isDismissed ? null : Icons.done)
),
title: this.widget.child
);
}
}
class _PopupMenu<T> : StatelessWidget {
public _PopupMenu(
Key key = null,
_PopupMenuRoute<T> route = null
) : base(key: key) {
this.route = route;
}
public readonly _PopupMenuRoute<T> route;
public override Widget build(BuildContext context) {
float unit = 1.0f / (this.route.items.Count + 1.5f);
List<Widget> children = new List<Widget>();
for (int i = 0; i < this.route.items.Count; i += 1) {
float start = (i + 1) * unit;
float end = (start + 1.5f * unit).clamp(0.0f, 1.0f);
Widget item = this.route.items[i];
if (this.route.initialValue != null && this.route.items[i].represents((T) this.route.initialValue)) {
item = new Container(
color: Theme.of(context).highlightColor,
child: item
);
}
children.Add(new FadeTransition(
opacity: new CurvedAnimation(
parent: this.route.animation,
curve: new Interval(start, end)
),
child: item
));
}
CurveTween opacity = new CurveTween(curve: new Interval(0.0f, 1.0f / 3.0f));
CurveTween width = new CurveTween(curve: new Interval(0.0f, unit));
CurveTween height = new CurveTween(curve: new Interval(0.0f, unit * this.route.items.Count));
Widget child = new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: PopupMenuUtils._kMenuMinWidth,
maxWidth: PopupMenuUtils._kMenuMaxWidth
),
child: new IntrinsicWidth(
stepWidth: PopupMenuUtils._kMenuWidthStep,
child: new SingleChildScrollView(
padding: EdgeInsets.symmetric(
vertical: PopupMenuUtils._kMenuVerticalPadding
),
child: new ListBody(children: children)
)
)
);
return new AnimatedBuilder(
animation: this.route.animation,
builder: (_, builderChild) => {
return new Opacity(
opacity: opacity.evaluate(this.route.animation),
child: new Material(
type: MaterialType.card,
elevation: this.route.elevation,
child: new Align(
alignment: Alignment.topRight,
widthFactor: width.evaluate(this.route.animation),
heightFactor: height.evaluate(this.route.animation),
child: builderChild
)
)
);
},
child: child
);
}
}
class _PopupMenuRouteLayout : SingleChildLayoutDelegate {
public _PopupMenuRouteLayout(RelativeRect position, float? selectedItemOffset) {
this.position = position;
this.selectedItemOffset = selectedItemOffset;
}
public readonly RelativeRect position;
public readonly float? selectedItemOffset;
public override BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
return BoxConstraints.loose(constraints.biggest -
new Offset(
PopupMenuUtils._kMenuScreenPadding * 2.0f,
PopupMenuUtils._kMenuScreenPadding * 2.0f));
}
public override Offset getPositionForChild(Size size, Size childSize) {
float y;
if (this.selectedItemOffset == null) {
y = this.position.top;
} else {
y = this.position.top + (size.height - this.position.top - this.position.bottom) / 2.0f -
this.selectedItemOffset.Value;
}
float x;
if (this.position.left > this.position.right) {
x = size.width - this.position.right - childSize.width;
} else if (this.position.left < this.position.right) {
x = this.position.left;
} else {
x = this.position.left;
}
if (x < PopupMenuUtils._kMenuScreenPadding) {
x = PopupMenuUtils._kMenuScreenPadding;
} else if (x + childSize.width > size.width - PopupMenuUtils._kMenuScreenPadding) {
x = size.width - childSize.width - PopupMenuUtils._kMenuScreenPadding;
}
if (y < PopupMenuUtils._kMenuScreenPadding) {
y = PopupMenuUtils._kMenuScreenPadding;
} else if (y + childSize.height > size.height - PopupMenuUtils._kMenuScreenPadding) {
y = size.height - childSize.height - PopupMenuUtils._kMenuScreenPadding;
}
return new Offset(x, y);
}
public override bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) {
return this.position != ((_PopupMenuRouteLayout) oldDelegate).position;
}
}
class _PopupMenuRoute<T> : PopupRoute {
public _PopupMenuRoute(
RelativeRect position = null,
List<PopupMenuEntry<T>> items = null,
object initialValue = null,
float elevation = 8.0f,
ThemeData theme = null
) {
this.position = position;
this.items = items;
this.initialValue = initialValue;
this.elevation = elevation;
this.theme = theme;
}
public readonly RelativeRect position;
public readonly List<PopupMenuEntry<T>> items;
public readonly object initialValue;
public readonly float elevation;
public readonly ThemeData theme;
public override Animation<float> createAnimation() {
return new CurvedAnimation(
parent: base.createAnimation(),
curve: Curves.linear,
reverseCurve: new Interval(0.0f, PopupMenuUtils._kMenuCloseIntervalEnd)
);
}
public override TimeSpan transitionDuration {
get { return PopupMenuUtils._kMenuDuration; }
}
public override bool barrierDismissible {
get { return true; }
}
public override Color barrierColor {
get { return null; }
}
public override Widget buildPage(BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation) {
float? selectedItemOffset = null;
if (this.initialValue != null) {
float y = PopupMenuUtils._kMenuVerticalPadding;
foreach (PopupMenuEntry<T> entry in this.items) {
if (entry.represents((T) this.initialValue)) {
selectedItemOffset = y + entry.height / 2.0f;
break;
}
y += entry.height;
}
}
Widget menu = new _PopupMenu<T>(route: this);
if (this.theme != null) {
menu = new Theme(data: this.theme, child: menu);
}
return MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
removeLeft: true,
removeRight: true,
child: new Builder(
builder: _ => new CustomSingleChildLayout(
layoutDelegate: new _PopupMenuRouteLayout(
this.position,
selectedItemOffset
),
child: menu
))
);
}
}
public static partial class PopupMenuUtils {
public static IPromise<T> showMenu<T>(
BuildContext context,
RelativeRect position,
List<PopupMenuEntry<T>> items,
T initialValue,
float elevation = 8.0f
) {
D.assert(context != null);
D.assert(items != null && items.isNotEmpty());
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
return Navigator.push(context, new _PopupMenuRoute<T>(
position: position,
items: items,
initialValue: initialValue,
elevation: elevation,
theme: Theme.of(context, shadowThemeOnly: true)
)).Then(result => (T) result);
}
}
public delegate void PopupMenuItemSelected<T>(T value);
public delegate void PopupMenuCanceled();
public delegate List<PopupMenuEntry<T>> PopupMenuItemBuilder<T>(BuildContext context);
public class PopupMenuButton<T> : StatefulWidget {
public PopupMenuButton(
Key key = null,
PopupMenuItemBuilder<T> itemBuilder = null,
T initialValue = default,
PopupMenuItemSelected<T> onSelected = null,
PopupMenuCanceled onCanceled = null,
string tooltip = null,
float elevation = 8.0f,
EdgeInsets padding = null,
Widget child = null,
Icon icon = null,
Offset offset = null
) : base(key: key) {
D.assert(itemBuilder != null);
D.assert(offset != null);
D.assert(!(child != null && icon != null));
this.itemBuilder = itemBuilder;
this.initialValue = initialValue;
this.onSelected = onSelected;
this.onCanceled = onCanceled;
this.tooltip = tooltip;
this.elevation = elevation;
this.padding = padding ?? EdgeInsets.all(8.0f);
this.child = child;
this.icon = icon;
this.offset = offset ?? Offset.zero;
}
public readonly PopupMenuItemBuilder<T> itemBuilder;
public readonly T initialValue;
public readonly PopupMenuItemSelected<T> onSelected;
public readonly PopupMenuCanceled onCanceled;
public readonly string tooltip;
public readonly float elevation;
public readonly EdgeInsets padding;
public readonly Widget child;
public readonly Icon icon;
public readonly Offset offset;
public override State createState() {
return new _PopupMenuButtonState<T>();
}
}
class _PopupMenuButtonState<T> : State<PopupMenuButton<T>> {
void showButtonMenu() {
RenderBox button = (RenderBox) this.context.findRenderObject();
RenderBox overlay = (RenderBox) Overlay.of(this.context).context.findRenderObject();
RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
button.localToGlobal(this.widget.offset, ancestor: overlay),
button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay)
),
Offset.zero & overlay.size
);
PopupMenuUtils.showMenu<T>(
context: this.context,
elevation: this.widget.elevation,
items: this.widget.itemBuilder(this.context),
initialValue: this.widget.initialValue,
position: position
)
.Then(newValue => {
if (!this.mounted) {
return;
}
if (newValue == null) {
if (this.widget.onCanceled != null) {
this.widget.onCanceled();
}
return;
}
if (this.widget.onSelected != null) {
this.widget.onSelected(newValue);
}
});
}
Icon _getIcon(RuntimePlatform platform) {
switch (platform) {
case RuntimePlatform.IPhonePlayer:
return new Icon(Icons.more_horiz);
default:
return new Icon(Icons.more_vert);
}
}
public override Widget build(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
return this.widget.child != null
? (Widget) new InkWell(
onTap: this.showButtonMenu,
child: this.widget.child
)
: new IconButton(
icon: this.widget.icon ?? this._getIcon(Theme.of(context).platform),
padding: this.widget.padding,
tooltip: this.widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
onPressed: this.showButtonMenu
);
}
}
}

11
Runtime/material/popup_menu.cs.meta


fileFormatVersion: 2
guid: ce8e103e04e044eeaa81c9c2ade4369b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

527
Runtime/material/switch.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using ImageUtils = Unity.UIWidgets.widgets.ImageUtils;
namespace Unity.UIWidgets.material {
enum _SwitchType {
material,
adaptive
}
public class Switch : StatefulWidget {
internal const float _kTrackHeight = 14.0f;
internal const float _kTrackWidth = 33.0f;
internal const float _kTrackRadius = _kTrackHeight / 2.0f;
internal const float _kThumbRadius = 10.0f;
internal const float _kSwitchWidth = _kTrackWidth - 2 * _kTrackRadius + 2 * Constants.kRadialReactionRadius;
internal const float _kSwitchHeight = 2 * Constants.kRadialReactionRadius + 8.0f;
internal const float _kSwitchHeightCollapsed = 2 * Constants.kRadialReactionRadius;
public Switch(
Key key = null,
bool? value = null,
ValueChanged<bool?> onChanged = null,
Color activeColor = null,
Color activeTrackColor = null,
Color inactiveThumbColor = null,
Color inactiveTrackColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null
) : this(
key: key,
value: value,
onChanged: onChanged,
activeColor: activeColor,
activeTrackColor: activeTrackColor,
inactiveThumbColor: inactiveThumbColor,
inactiveTrackColor: inactiveTrackColor,
activeThumbImage: activeThumbImage,
inactiveThumbImage: inactiveThumbImage,
materialTapTargetSize: materialTapTargetSize,
switchType: _SwitchType.material
) {
}
Switch(
Key key = null,
bool? value = null,
ValueChanged<bool?> onChanged = null,
Color activeColor = null,
Color activeTrackColor = null,
Color inactiveThumbColor = null,
Color inactiveTrackColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null,
_SwitchType switchType = _SwitchType.material
) : base(key: key) {
D.assert(value != null);
this.value = value.Value;
D.assert(onChanged != null);
this.onChanged = onChanged;
this.activeColor = activeColor;
this.activeTrackColor = activeTrackColor;
this.inactiveThumbColor = inactiveThumbColor;
this.inactiveTrackColor = inactiveTrackColor;
this.activeThumbImage = activeThumbImage;
this.inactiveThumbImage = inactiveThumbImage;
this.materialTapTargetSize = materialTapTargetSize;
this._switchType = switchType;
}
public static Switch adaptive(
Key key = null,
bool? value = null,
ValueChanged<bool?> onChanged = null,
Color activeColor = null,
Color activeTrackColor = null,
Color inactiveThumbColor = null,
Color inactiveTrackColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
MaterialTapTargetSize? materialTapTargetSize = null
) {
return new Switch(key: key,
value: value,
onChanged: onChanged,
activeColor: activeColor,
activeTrackColor: activeTrackColor,
inactiveThumbColor: inactiveThumbColor,
inactiveTrackColor: inactiveTrackColor,
activeThumbImage: activeThumbImage,
inactiveThumbImage: inactiveThumbImage,
materialTapTargetSize: materialTapTargetSize,
switchType: _SwitchType.adaptive
);
}
public readonly bool value;
public readonly ValueChanged<bool?> onChanged;
public readonly Color activeColor;
public readonly Color activeTrackColor;
public readonly Color inactiveThumbColor;
public readonly Color inactiveTrackColor;
public readonly ImageProvider activeThumbImage;
public readonly ImageProvider inactiveThumbImage;
public readonly MaterialTapTargetSize? materialTapTargetSize;
internal readonly _SwitchType _switchType;
public override State createState() {
return new _SwitchState();
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("value", value: this.value, ifTrue: "on", ifFalse: "off", showName: true));
properties.add(new ObjectFlagProperty<ValueChanged<bool>>("onChanged", this.onChanged, ifNull: "disabled"));
}
}
class _SwitchState : TickerProviderStateMixin<Switch> {
Size getSwitchSize(ThemeData theme) {
switch (this.widget.materialTapTargetSize ?? theme.materialTapTargetSize) {
case MaterialTapTargetSize.padded:
return new Size(Switch._kSwitchWidth, Switch._kSwitchHeight);
break;
case MaterialTapTargetSize.shrinkWrap:
return new Size(Switch._kSwitchWidth, Switch._kSwitchHeightCollapsed);
break;
}
D.assert(false);
return null;
}
Widget buildMaterialSwitch(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterial(context));
ThemeData theme = Theme.of(context);
bool isDark = theme.brightness == Brightness.dark;
Color activeThumbColor = this.widget.activeColor ?? theme.toggleableActiveColor;
Color activeTrackColor = this.widget.activeTrackColor ?? activeThumbColor.withAlpha(0x80);
Color inactiveThumbColor;
Color inactiveTrackColor;
if (this.widget.onChanged != null) {
Color black32 = new Color(0x52000000); // Black with 32% opacity
inactiveThumbColor = this.widget.inactiveThumbColor ??
(isDark ? Colors.grey.shade400 : Colors.grey.shade50);
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white30 : black32);
} else {
inactiveThumbColor = this.widget.inactiveThumbColor ??
(isDark ? Colors.grey.shade800 : Colors.grey.shade400);
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white10 : Colors.black12);
}
return new _SwitchRenderObjectWidget(
value: this.widget.value,
activeColor: activeThumbColor,
inactiveColor: inactiveThumbColor,
activeThumbImage: this.widget.activeThumbImage,
inactiveThumbImage: this.widget.inactiveThumbImage,
activeTrackColor: activeTrackColor,
inactiveTrackColor: inactiveTrackColor,
configuration: ImageUtils.createLocalImageConfiguration(context),
onChanged: this.widget.onChanged,
additionalConstraints: BoxConstraints.tight(this.getSwitchSize(theme)),
vsync: this
);
}
// Widget buildCupertinoSwitch(BuildContext context) {
// Size size = this.getSwitchSize(Theme.of(context));
// return new Container(
// width: size.width, // Same size as the Material switch.
// height: size.height,
// alignment: Alignment.center,
// child: CupertinoSwitch(
// value: this.widget.value,
// onChanged: this.widget.onChanged,
// activeColor: this.widget.activeColor
// )
// );
// }
public override Widget build(BuildContext context) {
switch (this.widget._switchType) {
case _SwitchType.material:
return this.buildMaterialSwitch(context);
case _SwitchType.adaptive: {
return this.buildMaterialSwitch(context);
// ThemeData theme = Theme.of(context);
// D.assert(theme.platform != null);
// switch (theme.platform) {
// case TargetPlatform.android:
// return buildMaterialSwitch(context);
// case TargetPlatform.iOS:
// return buildCupertinoSwitch(context);
// }
// break;
}
}
D.assert(false);
return null;
}
}
class _SwitchRenderObjectWidget : LeafRenderObjectWidget {
public _SwitchRenderObjectWidget(
Key key = null,
bool? value = null,
Color activeColor = null,
Color inactiveColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
Color activeTrackColor = null,
Color inactiveTrackColor = null,
ImageConfiguration configuration = null,
ValueChanged<bool?> onChanged = null,
TickerProvider vsync = null,
BoxConstraints additionalConstraints = null
) : base(key: key) {
D.assert(value != null);
this.value = value.Value;
this.activeColor = activeColor;
this.inactiveColor = inactiveColor;
this.activeThumbImage = activeThumbImage;
this.inactiveThumbImage = inactiveThumbImage;
this.activeTrackColor = activeTrackColor;
this.inactiveTrackColor = inactiveTrackColor;
this.configuration = configuration;
this.onChanged = onChanged;
this.vsync = vsync;
this.additionalConstraints = additionalConstraints;
}
public readonly bool value;
public readonly Color activeColor;
public readonly Color inactiveColor;
public readonly ImageProvider activeThumbImage;
public readonly ImageProvider inactiveThumbImage;
public readonly Color activeTrackColor;
public readonly Color inactiveTrackColor;
public readonly ImageConfiguration configuration;
public readonly ValueChanged<bool?> onChanged;
public readonly TickerProvider vsync;
public readonly BoxConstraints additionalConstraints;
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderSwitch(
value: this.value,
activeColor: this.activeColor,
inactiveColor: this.inactiveColor,
activeThumbImage: this.activeThumbImage,
inactiveThumbImage: this.inactiveThumbImage,
activeTrackColor: this.activeTrackColor,
inactiveTrackColor: this.inactiveTrackColor,
configuration: this.configuration,
onChanged: this.onChanged,
additionalConstraints: this.additionalConstraints,
vsync: this.vsync
);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObjectRaw) {
_RenderSwitch renderObject = (_RenderSwitch) renderObjectRaw;
renderObject.value = this.value;
renderObject.activeColor = this.activeColor;
renderObject.inactiveColor = this.inactiveColor;
renderObject.activeThumbImage = this.activeThumbImage;
renderObject.inactiveThumbImage = this.inactiveThumbImage;
renderObject.activeTrackColor = this.activeTrackColor;
renderObject.inactiveTrackColor = this.inactiveTrackColor;
renderObject.configuration = this.configuration;
renderObject.onChanged = this.onChanged;
renderObject.additionalConstraints = this.additionalConstraints;
renderObject.vsync = this.vsync;
}
}
class _RenderSwitch : RenderToggleable {
public _RenderSwitch(
bool? value = null,
Color activeColor = null,
Color inactiveColor = null,
ImageProvider activeThumbImage = null,
ImageProvider inactiveThumbImage = null,
Color activeTrackColor = null,
Color inactiveTrackColor = null,
ImageConfiguration configuration = null,
BoxConstraints additionalConstraints = null,
ValueChanged<bool?> onChanged = null,
TickerProvider vsync = null
) : base(
value: value,
tristate: false,
activeColor: activeColor,
inactiveColor: inactiveColor,
onChanged: onChanged,
additionalConstraints: additionalConstraints,
vsync: vsync
) {
this._activeThumbImage = activeThumbImage;
this._inactiveThumbImage = inactiveThumbImage;
this._activeTrackColor = activeTrackColor;
this._inactiveTrackColor = inactiveTrackColor;
this._configuration = configuration;
this._drag = new HorizontalDragGestureRecognizer {
onStart = this._handleDragStart,
onUpdate = this._handleDragUpdate,
onEnd = this._handleDragEnd,
};
}
public ImageProvider activeThumbImage {
get { return this._activeThumbImage; }
set {
if (value == this._activeThumbImage) {
return;
}
this._activeThumbImage = value;
this.markNeedsPaint();
}
}
ImageProvider _activeThumbImage;
public ImageProvider inactiveThumbImage {
get { return this._inactiveThumbImage; }
set {
if (value == this._inactiveThumbImage) {
return;
}
this._inactiveThumbImage = value;
this.markNeedsPaint();
}
}
ImageProvider _inactiveThumbImage;
public Color activeTrackColor {
get { return this._activeTrackColor; }
set {
D.assert(value != null);
if (value == this._activeTrackColor) {
return;
}
this._activeTrackColor = value;
this.markNeedsPaint();
}
}
Color _activeTrackColor;
public Color inactiveTrackColor {
get { return this._inactiveTrackColor; }
set {
D.assert(value != null);
if (value == this._inactiveTrackColor) {
return;
}
this._inactiveTrackColor = value;
this.markNeedsPaint();
}
}
Color _inactiveTrackColor;
public ImageConfiguration configuration {
get { return this._configuration; }
set {
D.assert(value != null);
if (value == this._configuration) {
return;
}
this._configuration = value;
this.markNeedsPaint();
}
}
ImageConfiguration _configuration;
public override void detach() {
this._cachedThumbPainter?.Dispose();
this._cachedThumbPainter = null;
base.detach();
}
float _trackInnerLength {
get { return this.size.width - 2.0f * Constants.kRadialReactionRadius; }
}
HorizontalDragGestureRecognizer _drag;
void _handleDragStart(DragStartDetails details) {
if (this.isInteractive) {
this.reactionController.forward();
}
}
void _handleDragUpdate(DragUpdateDetails details) {
if (this.isInteractive) {
this.position.curve = null;
this.position.reverseCurve = null;
float delta = details.primaryDelta.Value / this._trackInnerLength;
this.positionController.setValue(this.positionController.value + delta);
}
}
void _handleDragEnd(DragEndDetails details) {
if (this.position.value >= 0.5) {
this.positionController.forward();
} else {
this.positionController.reverse();
}
this.reactionController.reverse();
}
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(this.debugHandleEvent(evt, entry));
if (evt is PointerDownEvent && this.onChanged != null) {
this._drag.addPointer((PointerDownEvent) evt);
}
base.handleEvent(evt, entry);
}
Color _cachedThumbColor;
ImageProvider _cachedThumbImage;
BoxPainter _cachedThumbPainter;
BoxDecoration _createDefaultThumbDecoration(Color color, ImageProvider image) {
return new BoxDecoration(
color: color,
image: image == null ? null : new DecorationImage(image: image),
shape: BoxShape.circle,
boxShadow: ShadowConstants.kElevationToShadow[1]
);
}
bool _isPainting = false;
void _handleDecorationChanged() {
if (!this._isPainting) {
this.markNeedsPaint();
}
}
public override void paint(PaintingContext context, Offset offset) {
Canvas canvas = context.canvas;
bool isActive = this.onChanged != null;
float currentValue = this.position.value;
float visualPosition = currentValue;
Color trackColor = isActive
? Color.lerp(this.inactiveTrackColor, this.activeTrackColor, currentValue)
: this.inactiveTrackColor;
// Paint the track
Paint paint = new Paint {color = trackColor};
float trackHorizontalPadding = Constants.kRadialReactionRadius - Switch._kTrackRadius;
Rect trackRect = Rect.fromLTWH(
offset.dx + trackHorizontalPadding,
offset.dy + (this.size.height - Switch._kTrackHeight) / 2.0f,
this.size.width - 2.0f * trackHorizontalPadding,
Switch._kTrackHeight
);
RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(Switch._kTrackRadius));
canvas.drawRRect(trackRRect, paint);
Offset thumbPosition = new Offset(
Constants.kRadialReactionRadius + visualPosition * this._trackInnerLength,
this.size.height / 2.0f
);
this.paintRadialReaction(canvas, offset, thumbPosition);
try {
this._isPainting = true;
BoxPainter thumbPainter;
Color thumbColor = isActive
? Color.lerp(this.inactiveColor, this.activeColor, currentValue)
: this.inactiveColor;
ImageProvider thumbImage = isActive
? (currentValue < 0.5 ? this.inactiveThumbImage : this.activeThumbImage)
: this.inactiveThumbImage;
if (this._cachedThumbPainter == null || thumbColor != this._cachedThumbColor ||
thumbImage != this._cachedThumbImage) {
this._cachedThumbColor = thumbColor;
this._cachedThumbImage = thumbImage;
this._cachedThumbPainter = this._createDefaultThumbDecoration(thumbColor, thumbImage)
.createBoxPainter(this._handleDecorationChanged);
}
thumbPainter = this._cachedThumbPainter;
float inset = 1.0f - (currentValue - 0.5f).abs() * 2.0f;
float radius = Switch._kThumbRadius - inset;
thumbPainter.paint(
canvas,
thumbPosition + offset - new Offset(radius, radius),
this.configuration.copyWith(size: Size.fromRadius(radius))
);
} finally {
this._isPainting = false;
}
}
}
}

11
Runtime/material/switch.cs.meta


fileFormatVersion: 2
guid: 4d9cbabd047e4459c890af24af812425
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

153
Runtime/material/timer.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public enum DayPeriod {
am,
pm,
}
public class TimeOfDay : IEquatable<TimeOfDay> {
public TimeOfDay(int hour, int minute) {
this.hour = hour;
this.minute = minute;
}
public static TimeOfDay fromDateTime(DateTime time) {
return new TimeOfDay(
hour: time.Hour,
minute: time.Minute
);
}
public static TimeOfDay now() {
return TimeOfDay.fromDateTime(DateTime.Now);
}
public static readonly int hoursPerDay = 24;
public static readonly int hoursPerPeriod = 12;
public static readonly int minutesPerHour = 60;
public TimeOfDay replacing(int? hour = null, int? minute = null) {
D.assert(hour == null || (hour >= 0 && hour < hoursPerDay));
D.assert(minute == null || (minute >= 0 && minute < minutesPerHour));
return new TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute);
}
public readonly int hour;
public readonly int minute;
public DayPeriod period {
get { return this.hour < hoursPerPeriod ? DayPeriod.am : DayPeriod.pm; }
}
public int hourOfPeriod {
get { return this.hour - this.periodOffset; }
}
public int periodOffset {
get { return this.period == DayPeriod.am ? 0 : hoursPerPeriod; }
}
public string format(BuildContext context) {
D.assert(WidgetsD.debugCheckHasMediaQuery(context));
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
MaterialLocalizations localizations = MaterialLocalizations.of(context);
return localizations.formatTimeOfDay(
this,
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat
);
}
static string _addLeadingZeroIfNeeded(int value) {
if (value < 10) {
return "0" + value;
}
return value.ToString();
}
public bool Equals(TimeOfDay other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.hour == other.hour && this.minute == other.minute;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((TimeOfDay) obj);
}
public override int GetHashCode() {
unchecked {
return (this.hour * 397) ^ this.minute;
}
}
public static bool operator ==(TimeOfDay left, TimeOfDay right) {
return Equals(left, right);
}
public static bool operator !=(TimeOfDay left, TimeOfDay right) {
return !Equals(left, right);
}
public override string ToString() {
string hourLabel = _addLeadingZeroIfNeeded(this.hour);
string minuteLabel = _addLeadingZeroIfNeeded(this.minute);
return $"TimeOfDay({hourLabel}:{minuteLabel})";
}
}
public enum TimeOfDayFormat {
HH_colon_mm,
HH_dot_mm,
frenchCanadian,
H_colon_mm,
h_colon_mm_space_a,
a_space_h_colon_mm,
}
public enum HourFormat {
HH,
H,
h,
}
public static class HourFormatUtils {
public static HourFormat hourFormat(TimeOfDayFormat of) {
switch (of) {
case TimeOfDayFormat.h_colon_mm_space_a:
case TimeOfDayFormat.a_space_h_colon_mm:
return HourFormat.h;
case TimeOfDayFormat.H_colon_mm:
return HourFormat.H;
case TimeOfDayFormat.HH_dot_mm:
case TimeOfDayFormat.HH_colon_mm:
case TimeOfDayFormat.frenchCanadian:
return HourFormat.HH;
}
throw new Exception("unknown format: " + of);
}
}
}

11
Runtime/material/timer.cs.meta


fileFormatVersion: 2
guid: eeb5dc81b18e644e69b2b89cf48b8f3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

323
Runtime/widgets/localizations.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RSG;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {
class _Pending {
public _Pending(LocalizationsDelegate del, IPromise<object> futureValue) {
this.del = del;
this.futureValue = futureValue;
}
public readonly LocalizationsDelegate del;
public readonly IPromise<object> futureValue;
internal static IPromise<Dictionary<Type, object>> _loadAll(Locale locale,
IEnumerable<LocalizationsDelegate> allDelegates) {
Dictionary<Type, object> output = new Dictionary<Type, object>();
List<_Pending> pendingList = null;
HashSet<Type> types = new HashSet<Type>();
List<LocalizationsDelegate> delegates = new List<LocalizationsDelegate>();
foreach (LocalizationsDelegate del in allDelegates) {
if (!types.Contains(del.type) && del.isSupported(locale)) {
types.Add(del.type);
delegates.Add(del);
}
}
foreach (LocalizationsDelegate del in delegates) {
IPromise<object> inputValue = del.load(locale);
object completedValue = null;
IPromise<object> futureValue = inputValue.Then(value => { return completedValue = value; });
if (completedValue != null) {
Type type = del.type;
D.assert(!output.ContainsKey(type));
output[type] = completedValue;
} else {
pendingList = pendingList ?? new List<_Pending>();
pendingList.Add(new _Pending(del, futureValue));
}
}
if (pendingList == null) {
return Promise<Dictionary<Type, object>>.Resolved(output);
}
return Promise<object>.All(pendingList.Select(p => p.futureValue))
.Then(values => {
var list = values.ToList();
D.assert(list.Count == pendingList.Count);
for (int i = 0; i < list.Count; i += 1) {
Type type = pendingList[i].del.type;
D.assert(!output.ContainsKey(type));
output[type] = list[i];
}
return output;
});
}
}
public abstract class LocalizationsDelegate {
protected LocalizationsDelegate() {
}
public abstract bool isSupported(Locale locale);
public abstract IPromise<object> load(Locale locale);
public abstract bool shouldReload(LocalizationsDelegate old);
public abstract Type type { get; }
public override string ToString() {
return $"{this.GetType()}[{this.type}]";
}
}
public abstract class LocalizationsDelegate<T> : LocalizationsDelegate {
public override Type type {
get { return typeof(T); }
}
}
public abstract class WidgetsLocalizations {
static WidgetsLocalizations of(BuildContext context) {
return Localizations.of<WidgetsLocalizations>(context, typeof(WidgetsLocalizations));
}
}
class _WidgetsLocalizationsDelegate : LocalizationsDelegate<WidgetsLocalizations> {
public _WidgetsLocalizationsDelegate() {
}
public override bool isSupported(Locale locale) {
return true;
}
public override IPromise<object> load(Locale locale) {
return DefaultWidgetsLocalizations.load(locale);
}
public override bool shouldReload(LocalizationsDelegate old) {
return false;
}
public override string ToString() {
return "DefaultWidgetsLocalizations.delegate(en_US)";
}
}
public class DefaultWidgetsLocalizations : WidgetsLocalizations {
public DefaultWidgetsLocalizations() {
}
public static IPromise<object> load(Locale locale) {
return Promise<object>.Resolved(new DefaultWidgetsLocalizations());
}
public static readonly LocalizationsDelegate<WidgetsLocalizations> del = new _WidgetsLocalizationsDelegate();
}
class _LocalizationsScope : InheritedWidget {
public _LocalizationsScope(
Key key,
Locale locale,
_LocalizationsState localizationsState,
Dictionary<Type, object> typeToResources,
Widget child
) : base(key: key, child: child) {
D.assert(locale != null);
D.assert(localizationsState != null);
D.assert(typeToResources != null);
this.locale = locale;
this.localizationsState = localizationsState;
this.typeToResources = typeToResources;
}
public readonly Locale locale;
public readonly _LocalizationsState localizationsState;
public readonly Dictionary<Type, object> typeToResources;
public override bool updateShouldNotify(InheritedWidget old) {
return this.typeToResources != ((_LocalizationsScope) old).typeToResources;
}
}
public class Localizations : StatefulWidget {
public Localizations(
Key key = null,
Locale locale = null,
List<LocalizationsDelegate> delegates = null,
Widget child = null
) : base(key: key) {
D.assert(locale != null);
D.assert(delegates != null);
D.assert(delegates.Any(del => del is LocalizationsDelegate<WidgetsLocalizations>));
}
public static Localizations overrides(
Key key = null,
BuildContext context = null,
Locale locale = null,
List<LocalizationsDelegate> delegates = null,
Widget child = null
) {
List<LocalizationsDelegate> mergedDelegates = _delegatesOf(context);
if (delegates != null) {
mergedDelegates.InsertRange(0, delegates);
}
return new Localizations(
key: key,
locale: locale ?? Localizations.localeOf(context),
delegates: mergedDelegates,
child: child
);
}
public readonly Locale locale;
public readonly List<LocalizationsDelegate> delegates;
public readonly Widget child;
public static Locale localeOf(BuildContext context, bool nullOk = false) {
D.assert(context != null);
_LocalizationsScope scope =
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope));
if (nullOk && scope == null) {
return null;
}
D.assert((bool) (scope != null), "a Localizations ancestor was not found");
return scope.localizationsState.locale;
}
public static List<LocalizationsDelegate> _delegatesOf(BuildContext context) {
D.assert(context != null);
_LocalizationsScope scope =
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope));
D.assert(scope != null, "a Localizations ancestor was not found");
return new List<LocalizationsDelegate>(scope.localizationsState.widget.delegates);
}
public static T of<T>(BuildContext context, Type type) {
D.assert(context != null);
D.assert(type != null);
_LocalizationsScope scope =
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope));
if (scope != null && scope.localizationsState != null) {
return scope.localizationsState.resourcesFor<T>(type);
}
return default;
}
public override State createState() {
return new _LocalizationsState();
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Locale>("locale", this.locale));
properties.add(new EnumerableProperty<LocalizationsDelegate>("delegates", this.delegates));
}
}
class _LocalizationsState : State<Localizations> {
readonly GlobalKey _localizedResourcesScopeKey = GlobalKey.key();
Dictionary<Type, object> _typeToResources = new Dictionary<Type, object>();
public Locale locale {
get { return this._locale; }
}
Locale _locale;
public override void initState() {
base.initState();
this.load(this.widget.locale);
}
bool _anyDelegatesShouldReload(Localizations old) {
if (this.widget.delegates.Count != old.delegates.Count) {
return true;
}
List<LocalizationsDelegate> delegates = this.widget.delegates.ToList();
List<LocalizationsDelegate> oldDelegates = old.delegates.ToList();
for (int i = 0; i < delegates.Count; i += 1) {
LocalizationsDelegate del = delegates[i];
LocalizationsDelegate oldDelegate = oldDelegates[i];
if (del.GetType() != oldDelegate.GetType() || del.shouldReload(oldDelegate)) {
return true;
}
}
return false;
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
Localizations old = (Localizations) oldWidget;
base.didUpdateWidget(old);
if (this.widget.locale != old.locale
|| (this.widget.delegates == null && old.delegates != null)
|| (this.widget.delegates != null && old.delegates == null)
|| (this.widget.delegates != null && this._anyDelegatesShouldReload(old))) {
this.load(this.widget.locale);
}
}
void load(Locale locale) {
var delegates = this.widget.delegates;
if (delegates == null || delegates.isEmpty()) {
this._locale = locale;
return;
}
Dictionary<Type, object> typeToResources = null;
IPromise<Dictionary<Type, object>> typeToResourcesFuture = _Pending._loadAll(locale, delegates)
.Then(value => { return typeToResources = value; });
if (typeToResources != null) {
this._typeToResources = typeToResources;
this._locale = locale;
} else {
// WidgetsBinding.instance.deferFirstFrameReport();
typeToResourcesFuture.Then(value => {
// WidgetsBinding.instance.allowFirstFrameReport();
if (!this.mounted) {
return;
}
this.setState(() => {
this._typeToResources = value;
this._locale = locale;
});
});
}
}
public T resourcesFor<T>(Type type) {
D.assert(type != null);
T resources = (T) this._typeToResources[type];
return resources;
}
public override Widget build(BuildContext context) {
if (this._locale == null) {
return new Container();
}
return new _LocalizationsScope(
key: this._localizedResourcesScopeKey,
locale: this._locale,
localizationsState: this,
typeToResources: this._typeToResources,
child: this.widget.child
);
}
}
}

11
Runtime/widgets/localizations.cs.meta


fileFormatVersion: 2
guid: 40b3aee9af16a4b40b16b463e6999452
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

400
Samples/UIWidgetsGallery/gallery/home.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RSG;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace UIWidgetsGallery.gallery {
public static class HomeUtils {
internal static readonly Color _kUIWidgetsBlue = new Color(0xFF003D75);
internal const float _kDemoItemHeight = 64.0f;
internal static TimeSpan _kFrontLayerSwitchDuration = new TimeSpan(0, 0, 0, 0, 300);
}
class _UIWidgetsLogo : StatelessWidget {
public _UIWidgetsLogo(Key key = null) : base(key: key) {
}
public override Widget build(BuildContext context) {
return new Center(
child: new Container(
width: 34.0f,
height: 34.0f,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage(
"logos/unity.png")
)
)
)
);
}
}
class _CategoryItem : StatelessWidget {
public _CategoryItem(
Key key = null,
GalleryDemoCategory category = null,
VoidCallback onTap = null
) : base(key: key) {
this.category = category;
this.onTap = onTap;
}
public readonly GalleryDemoCategory category;
public readonly VoidCallback onTap;
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
bool isDark = theme.brightness == Brightness.dark;
return new RepaintBoundary(
child: new RawMaterialButton(
padding: EdgeInsets.zero,
splashColor: theme.primaryColor.withOpacity(0.12f),
highlightColor: Colors.transparent,
onPressed: this.onTap,
child: new Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget> {
new Padding(
padding: EdgeInsets.all(6.0f),
child: new Icon(
this.category.icon,
size: 60.0f,
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue
)
),
new SizedBox(height: 10.0f),
new Container(
height: 48.0f,
alignment: Alignment.center,
child: new Text(
this.category.name,
textAlign: TextAlign.center,
style: theme.textTheme.subhead.copyWith(
fontFamily: "GoogleSans",
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue
)
)
)
}
)
)
);
}
}
class _CategoriesPage : StatelessWidget {
public _CategoriesPage(
Key key = null,
IEnumerable<GalleryDemoCategory> categories = null,
ValueChanged<GalleryDemoCategory> onCategoryTap = null
) : base(key: key) {
this.categories = categories;
this.onCategoryTap = onCategoryTap;
}
public readonly IEnumerable<GalleryDemoCategory> categories;
public readonly ValueChanged<GalleryDemoCategory> onCategoryTap;
public override Widget build(BuildContext context) {
float aspectRatio = 160.0f / 180.0f;
List<GalleryDemoCategory> categoriesList = this.categories.ToList();
int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3;
return new SingleChildScrollView(
key: new PageStorageKey<string>("categories"),
child: new LayoutBuilder(
builder: (_, constraints) => {
float columnWidth = constraints.biggest.width / columnCount;
float rowHeight = Mathf.Min(225.0f, columnWidth * aspectRatio);
int rowCount = (categoriesList.Count + columnCount - 1) / columnCount;
return new RepaintBoundary(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: Enumerable.Range(0, rowCount).Select(rowIndex => {
int columnCountForRow = rowIndex == rowCount - 1
? categoriesList.Count - columnCount * Mathf.Max(0, rowCount - 1)
: columnCount;
return (Widget) new Row(
children: Enumerable.Range(0, columnCountForRow).Select(columnIndex => {
int index = rowIndex * columnCount + columnIndex;
GalleryDemoCategory category = categoriesList[index];
return (Widget) new SizedBox(
width: columnWidth,
height: rowHeight,
child: new _CategoryItem(
category: category,
onTap: () => { this.onCategoryTap(category); }
)
);
}).ToList()
);
}).ToList()
)
);
}
)
);
}
}
class _DemoItem : StatelessWidget {
public _DemoItem(Key key = null, GalleryDemo demo = null) : base(key: key) {
this.demo = demo;
}
public readonly GalleryDemo demo;
void _launchDemo(BuildContext context) {
if (this.demo.routeName != null) {
Navigator.pushNamed(context, this.demo.routeName);
}
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
bool isDark = theme.brightness == Brightness.dark;
float textScaleFactor = MediaQuery.textScaleFactorOf(context);
List<Widget> titleChildren = new List<Widget> {
new Text(
this.demo.title,
style: theme.textTheme.subhead.copyWith(
color: isDark ? Colors.white : new Color(0xFF202124)
)
),
};
if (this.demo.subtitle != null) {
titleChildren.Add(
new Text(
this.demo.subtitle,
style: theme.textTheme.body1.copyWith(
color: isDark ? Colors.white : new Color(0xFF60646B)
)
)
);
}
return new RawMaterialButton(
padding: EdgeInsets.zero,
splashColor: theme.primaryColor.withOpacity(0.12f),
highlightColor: Colors.transparent,
onPressed: () => { this._launchDemo(context); },
child: new Container(
constraints: new BoxConstraints(minHeight: HomeUtils._kDemoItemHeight * textScaleFactor),
child: new Row(
children: new List<Widget> {
new Container(
width: 56.0f,
height: 56.0f,
alignment: Alignment.center,
child: new Icon(
this.demo.icon,
size: 24.0f,
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue
)
),
new Expanded(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: titleChildren
)
),
new SizedBox(width: 44.0f),
}
)
)
);
}
}
class _DemosPage : StatelessWidget {
public _DemosPage(GalleryDemoCategory category) {
this.category = category;
}
public readonly GalleryDemoCategory category;
public override Widget build(BuildContext context) {
float windowBottomPadding = MediaQuery.of(context).padding.bottom;
return new KeyedSubtree(
key: new ValueKey<string>("GalleryDemoList"),
child: new ListView(
key: new PageStorageKey<string>(this.category.name),
padding: EdgeInsets.only(top: 8.0f, bottom: windowBottomPadding),
children: DemoUtils.kGalleryCategoryToDemos[this.category]
.Select(demo => (Widget) new _DemoItem(demo: demo)).ToList()
)
);
}
}
public class GalleryHome : StatefulWidget {
public GalleryHome(
Key key = null,
bool testMode = false,
Widget optionsPage = null
) : base(key: key) {
this.testMode = testMode;
this.optionsPage = optionsPage;
}
public readonly Widget optionsPage;
public readonly bool testMode;
public static bool showPreviewBanner = true;
public override State createState() {
// return new _GalleryHomeState();
return null;
}
}
// class _GalleryHomeState : SingleTickerProviderStateMixin<GalleryHome> {
// static readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
// AnimationController _controller;
// GalleryDemoCategory _category;
//
// static Widget _topHomeLayout(Widget currentChild, List<Widget> previousChildren) {
// List<Widget> children = previousChildren;
// if (currentChild != null) {
// children = children.ToList();
// children.Add(currentChild);
// }
//
// return new Stack(
// children: children,
// alignment: Alignment.topCenter
// );
// }
//
// static const AnimatedSwitcherLayoutBuilder _centerHomeLayout = AnimatedSwitcher.defaultLayoutBuilder;
//
// public override void initState() {
// base.initState();
// this._controller = new AnimationController(
// duration: new TimeSpan(0, 0, 0, 0, 600),
// debugLabel: "preview banner",
// vsync: this
// );
// this._controller.forward();
// }
//
// public override void dispose() {
// this._controller.dispose();
// base.dispose();
// }
//
// public override Widget build(BuildContext context) {
// ThemeData theme = Theme.of(context);
// bool isDark = theme.brightness == Brightness.dark;
// MediaQueryData media = MediaQuery.of(context);
// bool centerHome = media.orientation == Orientation.portrait && media.size.height < 800.0;
//
// Curve switchOutCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
// Curve switchInCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
//
// Widget home = new Scaffold(
// key: _scaffoldKey,
// backgroundColor: isDark ? HomeUtils._kUIWidgetsBlue : theme.primaryColor,
// body: new SafeArea(
// bottom: false,
// child: new WillPopScope(
// onWillPop: () => {
// // Pop the category page if Android back button is pressed.
// if (this._category != null) {
// this.setState(() => this._category = null);
// return Promise<bool>.Resolved(false);
// }
// return Promise<bool>.Resolved(true);
// },
// child: new Backdrop(
// backTitle: new Text("Options"),
// backLayer: this.widget.optionsPage,
// frontAction: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// switchOutCurve: switchOutCurve,
// switchInCurve: switchInCurve,
// child: this._category == null
// ? new _UIWidgetsLogo()
// : new IconButton(
// icon: new BackButtonIcon(),
// tooltip: "Back",
// onPressed: () => this.setState(() => this._category = null)
// )
// ),
// frontTitle: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// child: this._category == null
// ? new Text("Flutter gallery")
// : new Text(this._category.name)
// ),
// frontHeading: this.widget.testMode ? null : new Container(height: 24.0f),
// frontLayer: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// switchOutCurve: switchOutCurve,
// switchInCurve: switchInCurve,
// layoutBuilder: centerHome ? _centerHomeLayout : _topHomeLayout,
// child: this._category != null
// ? new _DemosPage(_category)
// : new _CategoriesPage(
// categories: DemoUtils.kAllGalleryDemoCategories,
// onCategoryTap: (GalleryDemoCategory category) => {
// this.setState(() => this._category = category);
// }
// )
// )
// )
// )
// )
// );
//
// D.assert(() => {
// GalleryHome.showPreviewBanner = false;
// return true;
// });
//
// if (GalleryHome.showPreviewBanner) {
// home = new Stack(
// fit: StackFit.expand,
// children: new List<Widget> {
// home,
// new FadeTransition(
// opacity: new CurvedAnimation(parent: this._controller, curve: Curves.easeInOut),
// child: new Banner(
// message: "PREVIEW",
// location: BannerLocation.topEnd
// )
// )
// }
// );
// }
// home = new AnnotatedRegion<SystemUiOverlayStyle>(
// child: home,
// value: SystemUiOverlayStyle.light
// );
//
// return home;
// }
// }
}

11
Samples/UIWidgetsGallery/gallery/home.cs.meta


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