浏览代码
Merge pull request #75 from Unity-Technologies/zxw/gallery
Merge pull request #75 from Unity-Technologies/zxw/gallery
add the main app for gallery/zgh-devtools
GitHub
4 年前
当前提交
95cd0354
共有 56 个文件被更改,包括 3782 次插入 和 37 次删除
-
23Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs
-
30com.unity.uiwidgets/Runtime/material/expansion_panel.cs
-
2com.unity.uiwidgets/Runtime/material/flat_button.cs
-
2com.unity.uiwidgets/Runtime/material/raised_button.cs
-
2com.unity.uiwidgets/Runtime/painting/edge_insets.cs
-
1com.unity.uiwidgets/Runtime/widgets/animated_size.cs
-
15com.unity.uiwidgets/Runtime/widgets/navigator.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery.meta
-
87Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs.meta
-
172Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs.meta
-
69Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs.meta
-
52Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/LongPressSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/LongPressSample.cs.meta
-
228Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/NavigationSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/NavigationSample.cs.meta
-
45Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/PageViewSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/PageViewSample.cs.meta
-
59Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ScrollbarSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ScrollbarSample.cs.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model.meta
-
107Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/app_state_model.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/app_state_model.cs.meta
-
46Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/product.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/product.cs.meta
-
285Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/products_repository.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/products_repository.cs.meta
-
148Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/scoped_model.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/model/scoped_model.cs.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/supplemental.meta
-
70Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/about.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/about.cs.meta
-
411Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/backdrop.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/backdrop.cs.meta
-
195Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/demos.cs.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/home.cs.meta
-
48Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/icons.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/icons.cs.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/options.cs.meta
-
158Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/scales.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/scales.cs.meta
-
95Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/themes.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/themes.cs.meta
-
96Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/updater.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/updater.cs.meta
-
192Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/app.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/app.cs.meta
-
418Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/home.cs
-
632Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/options.cs
|
|||
using UIWidgetsGallery.gallery; |
|||
using Unity.UIWidgets.engine2; |
|||
//using Unity.UIWidgets.material;
|
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
/*protected override Widget createWidget() { |
|||
return new GalleryApp(); |
|||
}*/ |
|||
protected override void main() { |
|||
ui_.runApp(new GalleryApp()); |
|||
} |
|||
/*protected override void OnEnable() { |
|||
FontManager.instance.addFont(Resources.Load<Font>("fonts/MaterialIcons-Regular"), "Material Icons"); |
|||
FontManager.instance.addFont(Resources.Load<Font>("fonts/GalleryIcons"), "GalleryIcons"); |
|||
|
|||
FontManager.instance.addFont(Resources.Load<Font>("fonts/CupertinoIcons"), "CupertinoIcons"); |
|||
FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/SF-Pro-Text-Regular"), ".SF Pro Text", FontWeight.w400); |
|||
FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/SF-Pro-Text-Semibold"), ".SF Pro Text", FontWeight.w600); |
|||
FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/SF-Pro-Text-Bold"), ".SF Pro Text", FontWeight.w700); |
|||
|
|||
protected new void OnEnable() { |
|||
}*/ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fb97b78a8c204fbb9c9dbf667cb23004 |
|||
timeCreated: 1612342718 |
|
|||
fileFormatVersion: 2 |
|||
guid: 20b07a92c4c64919aa3adf9322758a65 |
|||
timeCreated: 1612322595 |
|
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class CustomPaintSample : UIWidgetsPanel { |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new Unity.UIWidgets.widgets.CustomPaint( |
|||
child: new Container(width: 300, height: 300, color: new Color(0XFFFFFFFF)), |
|||
foregroundPainter: new GridPainter(null) |
|||
), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
public class GridPainter : AbstractCustomPainter { |
|||
public GridPainter(Listenable repaint) : base(repaint) { |
|||
} |
|||
|
|||
public override void paint(Canvas canvas, Size size) { |
|||
int numGrid = 4; |
|||
var paint = new Paint(); |
|||
paint.color = new Color(0xFFFF0000); |
|||
paint.strokeWidth = 2; |
|||
paint.style = PaintingStyle.stroke; |
|||
for (int i = 1; i < numGrid; i++) { |
|||
float offsetY = size.height * i / numGrid; |
|||
canvas.drawLine(new Offset(0, offsetY), new Offset(size.width, offsetY), |
|||
paint); |
|||
} |
|||
|
|||
for (int i = 1; i < numGrid; i++) { |
|||
float offsetx = size.width * i / numGrid; |
|||
canvas.drawLine(new Offset(offsetx, 0), new Offset(offsetx, size.height), |
|||
paint); |
|||
} |
|||
|
|||
|
|||
// draw a arrow line
|
|||
canvas.save(); |
|||
canvas.rotate(0.4f); |
|||
canvas.scale(2, 2); |
|||
canvas.translate(50, 50); |
|||
canvas.drawLine(new Offset(0, 0), new Offset(100, 0), |
|||
new Paint() { |
|||
color = new Color(0xFFFF0000), |
|||
strokeWidth = 2, |
|||
style = PaintingStyle.stroke |
|||
}); |
|||
var path = new Path(); |
|||
var arrowPaint = new Paint() { |
|||
color = new Color(0xFFFF0000), |
|||
style = PaintingStyle.fill |
|||
}; |
|||
path.moveTo(100, 0); |
|||
path.lineTo(100, 5); |
|||
path.lineTo(120, 0); |
|||
path.lineTo(100, -5); |
|||
path.close(); |
|||
canvas.drawPath(path, arrowPaint); |
|||
canvas.restore(); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldDelegate) { |
|||
return false; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 64240ba829347de43abdb2daa8488bc6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Material = Unity.UIWidgets.material.Material; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ExpansionPanelSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() { |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
int testCaseId = 1; |
|||
|
|||
readonly List<Widget> testCases = new List<Widget> { |
|||
new SingleChildScrollWidget(), |
|||
new ExpansionPanelWidget() |
|||
}; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new MaterialApp( |
|||
home: this.testCases[this.testCaseId] |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
class SingleChildScrollWidget : StatefulWidget { |
|||
public SingleChildScrollWidget(Key key = null) : base(key) { |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new SingleChildScrollWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class SingleChildScrollWidgetState : State<SingleChildScrollWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Material( |
|||
child: new SingleChildScrollView( |
|||
child: new Container( |
|||
width: 40.0f, |
|||
height: 40.0f, |
|||
constraints: BoxConstraints.tight(new Size(40, 600)), |
|||
color:Colors.red, |
|||
child: new Center(child: new Text("Beijing")) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class ExpansionPanelWidget : StatefulWidget { |
|||
public ExpansionPanelWidget(Key key = null) : base(key) { |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new ExpansionPanelWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class ExpansionPanelWidgetState : State<ExpansionPanelWidget> { |
|||
readonly List<bool> isExpand = new List<bool> {false, false}; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Material( |
|||
child: new SingleChildScrollView( |
|||
child: new ExpansionPanelList( |
|||
expansionCallback: (int _index, bool _isExpanded) => { |
|||
Debug.Log("<tile " + _index + "> from [" + (_isExpanded ? "Open" : "Close") + "]" + |
|||
" to [" + (_isExpanded ? "Close" : "Open") + "]"); |
|||
|
|||
this.isExpand[_index] = !_isExpanded; |
|||
this.setState(() => { }); |
|||
}, |
|||
children: new List<ExpansionPanel> { |
|||
new ExpansionPanel( |
|||
headerBuilder: (BuildContext subContext, bool isExpanded) => { |
|||
return new Container( |
|||
color: Colors.black45, |
|||
child: new Center( |
|||
child: new Text("Beijing") |
|||
) |
|||
); |
|||
}, |
|||
body: new Container( |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Beijing") |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
), |
|||
isExpanded: this.isExpand[0] |
|||
), |
|||
new ExpansionPanel( |
|||
headerBuilder: (BuildContext subContext, bool isExpanded) => { |
|||
return new Container( |
|||
color: Colors.black45, |
|||
child: new Center( |
|||
child: new Text("Hebei") |
|||
) |
|||
); |
|||
}, |
|||
body: new Container( |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Tianjin") |
|||
) |
|||
) |
|||
), |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Shijiazhuang") |
|||
) |
|||
) |
|||
), |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Zhumadian") |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
), |
|||
isExpanded: this.isExpand[1] |
|||
), |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 49545bd84f0a8614e866467b68490383 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using UnityEngine.Networking; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
public class HttpRequestSample : UIWidgetsPanel |
|||
{ |
|||
protected override void main() { |
|||
ui_.runApp(new MaterialApp( |
|||
title: "Http Request Sample", |
|||
home: new Scaffold( |
|||
body:new AsyncRequestWidget(this.gameObject) |
|||
) |
|||
)); |
|||
} |
|||
} |
|||
|
|||
public class AsyncRequestWidget : StatefulWidget { |
|||
|
|||
public readonly GameObject gameObjOfUIWidgetsPanel; |
|||
|
|||
public AsyncRequestWidget(GameObject gameObjOfUiWidgetsPanel, Key key = null) : base(key) { |
|||
this.gameObjOfUIWidgetsPanel = gameObjOfUiWidgetsPanel; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _AsyncRequestWidgetState(); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class TimeData { |
|||
public long currentFileTime; |
|||
} |
|||
|
|||
class _AsyncRequestWidgetState : State<AsyncRequestWidget> { |
|||
|
|||
long _fileTime; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
var isolate = Isolate.current; |
|||
|
|||
return new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: new List<Widget>() { |
|||
new FlatButton(child: new Text("Click To Get Time"), onPressed: () => { |
|||
UnityWebRequest www = UnityWebRequest.Get("http://worldclockapi.com/api/json/est/now"); |
|||
var asyncOperation = www.SendWebRequest(); |
|||
asyncOperation.completed += operation => { |
|||
var timeData = JsonUtility.FromJson<TimeData>(www.downloadHandler.text); |
|||
using(Isolate.getScope(isolate)) |
|||
{ |
|||
this.setState(() => { this._fileTime = timeData.currentFileTime; }); |
|||
} |
|||
|
|||
}; |
|||
}), |
|||
new Text($"current file time: {this._fileTime}") |
|||
}); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b8fdebced4875694db8d21968f82b2c9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using uiwidgets; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class LongPressSample : UIWidgetsPanel { |
|||
protected override void main() { |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new LongPressSampleWidget(), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class LongPressSampleWidget : StatefulWidget { |
|||
public override State createState() { |
|||
return new _LongPressSampleWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class _LongPressSampleWidgetState : State<LongPressSampleWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new GestureDetector( |
|||
onLongPressStart: (value) => { Debug.Log($"Long Press Drag Start: {value}"); }, |
|||
onLongPressMoveUpdate: (value) => { Debug.Log($"Long Press Drag Update: {value}"); }, |
|||
onLongPressEnd: (value) => { Debug.Log($"Long Press Drag Up: {value}"); }, |
|||
onLongPressUp: () => { Debug.Log($"Long Press Up"); }, |
|||
onLongPress: () => { Debug.Log($"Long Press"); }, |
|||
child: new Center( |
|||
child: new Container( |
|||
width: 200, |
|||
height: 200, |
|||
color: Colors.blue |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b77689aad2545fb4bb66d5d41126fab2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using DialogUtils = Unity.UIWidgets.widgets.DialogUtils; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class NavigationSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
initialRoute: "/", |
|||
textStyle: new TextStyle(fontSize: 24), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext subContext, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(subContext), |
|||
transitionsBuilder: (BuildContext subContext, Animation<float> |
|||
animation, Animation<float> secondaryAnimation, Widget child) => |
|||
new _FadeUpwardsPageTransition( |
|||
routeAnimation: animation, |
|||
child: child |
|||
) |
|||
), |
|||
routes: new Dictionary<string, WidgetBuilder> { |
|||
{"/", (subContext) => new HomeScreen()}, |
|||
{"/detail", (subContext) => new DetailScreen()} |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget { |
|||
public CustomButton( |
|||
Key key = null, |
|||
GestureTapCallback onPressed = null, |
|||
EdgeInsets padding = null, |
|||
Color backgroundColor = null, |
|||
Widget child = null |
|||
) : base(key: key) { |
|||
this.onPressed = onPressed; |
|||
this.padding = padding ?? EdgeInsets.all(8.0f); |
|||
this.backgroundColor = backgroundColor ?? Colors.white; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly GestureTapCallback onPressed; |
|||
public readonly EdgeInsets padding; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new GestureDetector( |
|||
onTap: this.onPressed, |
|||
child: new Container( |
|||
padding: this.padding, |
|||
color: this.backgroundColor, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class HomeScreen : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new NavigationPage( |
|||
body: new Container( |
|||
color: new Color(0xFF888888), |
|||
child: new Center( |
|||
child: new CustomButton(onPressed: () => { Navigator.pushNamed(context, "/detail"); }, |
|||
child: new Text("Go to Detail")) |
|||
)), |
|||
title: "Home" |
|||
); |
|||
} |
|||
} |
|||
|
|||
class DetailScreen : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new NavigationPage( |
|||
body: new Container( |
|||
color: new Color(0xFF1389FD), |
|||
child: new Center( |
|||
child: new Column( |
|||
children: new List<Widget>() { |
|||
new CustomButton(onPressed: () => { Navigator.pop<object>(context); }, child: new Text("Back")), |
|||
new CustomButton( |
|||
onPressed: () => { |
|||
_Dialog.showDialog(context, builder: (BuildContext c) => new Dialog()); |
|||
}, child: new Text("Show Dialog")) |
|||
} |
|||
) |
|||
)), |
|||
title: "Detail"); |
|||
} |
|||
} |
|||
|
|||
class Dialog : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new Center(child: new Container( |
|||
color: new Color(0xFFFF0000), |
|||
width: 100, |
|||
height: 80, |
|||
child: new Center( |
|||
child: new Text("Hello Dialog") |
|||
))); |
|||
} |
|||
} |
|||
|
|||
class _FadeUpwardsPageTransition : StatelessWidget { |
|||
internal _FadeUpwardsPageTransition( |
|||
Key key = null, |
|||
Animation<float> routeAnimation = null, // The route's linear 0.0 - 1.0 animation.
|
|||
Widget child = null |
|||
) : base(key: key) { |
|||
this._positionAnimation = _bottomUpTween.chain(_fastOutSlowInTween).animate(routeAnimation); |
|||
this._opacityAnimation = _easeInTween.animate(routeAnimation); |
|||
this.child = child; |
|||
} |
|||
|
|||
static Tween<Offset> _bottomUpTween = new OffsetTween( |
|||
begin: new Offset(0.0f, 0.25f), |
|||
end: Offset.zero |
|||
); |
|||
|
|||
static Animatable<float> _fastOutSlowInTween = new CurveTween(curve: Curves.fastOutSlowIn); |
|||
static Animatable<float> _easeInTween = new CurveTween(curve: Curves.easeIn); |
|||
|
|||
readonly Animation<Offset> _positionAnimation; |
|||
readonly Animation<float> _opacityAnimation; |
|||
public readonly Widget child; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new SlideTransition( |
|||
position: this._positionAnimation, |
|||
child: new FadeTransition( |
|||
opacity: this._opacityAnimation, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class NavigationPage : StatelessWidget { |
|||
public readonly Widget body; |
|||
public readonly string title; |
|||
|
|||
public NavigationPage(Widget body = null, string title = null) { |
|||
this.title = title; |
|||
this.body = body; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
Widget back = null; |
|||
if (Navigator.of(context).canPop()) { |
|||
back = new CustomButton(onPressed: () => { Navigator.pop<object>(context); }, |
|||
child: new Text("Go Back")); |
|||
back = new Column(mainAxisAlignment: MainAxisAlignment.center, children: new List<Widget>() {back}); |
|||
} |
|||
|
|||
|
|||
return new Container( |
|||
child: new Column( |
|||
children: new List<Widget>() { |
|||
new ConstrainedBox(constraints: new BoxConstraints(maxHeight: 80), |
|||
child: new DecoratedBox( |
|||
decoration: new BoxDecoration(color: new Color(0XFFE1ECF4)), |
|||
child: new NavigationToolbar(leading: back, |
|||
middle: new Text(this.title, textAlign: TextAlign.center)))), |
|||
new Flexible(child: this.body) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
static class _Dialog { |
|||
public static void showDialog(BuildContext context, |
|||
bool barrierDismissible = true, WidgetBuilder builder = null) { |
|||
DialogUtils.showGeneralDialog<object>( |
|||
context: context, |
|||
pageBuilder: (BuildContext buildContext, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => { |
|||
return builder(buildContext); |
|||
}, |
|||
barrierDismissible: barrierDismissible, |
|||
barrierColor: new Color(0x8A000000), |
|||
transitionDuration: TimeSpan.FromMilliseconds(150), |
|||
transitionBuilder: _buildMaterialDialogTransitions |
|||
); |
|||
} |
|||
|
|||
static Widget _buildMaterialDialogTransitions(BuildContext context, |
|||
Animation<float> animation, Animation<float> secondaryAnimation, Widget child) { |
|||
return new FadeTransition( |
|||
opacity: new CurvedAnimation( |
|||
parent: animation, |
|||
curve: Curves.easeOut |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 351f52ea9be972a48ad92328d8a99951 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class PageViewSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new Container( |
|||
width: 200, |
|||
height: 400, |
|||
child: new PageView( |
|||
children: new List<Widget>() { |
|||
new Container( |
|||
color: new Color(0xFFE91E63) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF00BCD4) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF673AB7) |
|||
) |
|||
} |
|||
)), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dfec4b1201ff9494e83d2f2cc6e22f82 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ScrollbarSample : UIWidgetsPanel { |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new Container( |
|||
decoration: new BoxDecoration( |
|||
border: Border.all(color: new Color(0xFFFFFF00)) |
|||
), |
|||
child: new Scrollbar( |
|||
child: new ListView( |
|||
children: new List<Widget> { |
|||
new Container(height: 40.0f, child: new Text("0")), |
|||
new Container(height: 40.0f, child: new Text("1")), |
|||
new Container(height: 40.0f, child: new Text("2")), |
|||
new Container(height: 40.0f, child: new Text("3")), |
|||
new Container(height: 40.0f, child: new Text("4")), |
|||
new Container(height: 40.0f, child: new Text("5")), |
|||
new Container(height: 40.0f, child: new Text("6")), |
|||
new Container(height: 40.0f, child: new Text("7")), |
|||
new Container(height: 40.0f, child: new Text("8")), |
|||
new Container(height: 40.0f, child: new Text("9")), |
|||
new Container(height: 40.0f, child: new Text("10")), |
|||
new Container(height: 40.0f, child: new Text("11")), |
|||
new Container(height: 40.0f, child: new Text("12")), |
|||
new Container(height: 40.0f, child: new Text("13")), |
|||
new Container(height: 40.0f, child: new Text("14")), |
|||
new Container(height: 40.0f, child: new Text("15")), |
|||
new Container(height: 40.0f, child: new Text("16")), |
|||
new Container(height: 40.0f, child: new Text("17")), |
|||
} |
|||
) |
|||
) |
|||
), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0666abb393df1e44bb00b1cff94ad6ca |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 14605fd6a2e647e5a40284b48310def7 |
|||
timeCreated: 1612342746 |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UIWidgetsGallery.demo.shrine.model |
|||
{ |
|||
public static class AppStateModelUtils |
|||
{ |
|||
public static readonly float _salesTaxRate = 0.06f; |
|||
public static readonly float _shippingCostPerItem = 7.0f; |
|||
} |
|||
|
|||
public class AppStateModel : Model |
|||
{ |
|||
private List<Product> _availableProducts; |
|||
|
|||
private Category _selectedCategory = Category.all; |
|||
|
|||
private Dictionary<int, int> _productsInCart = new Dictionary<int, int> { }; |
|||
|
|||
private Dictionary<int, int> productsInCart => new Dictionary<int, int>(this._productsInCart); |
|||
|
|||
public int totalCartQuantity => this._productsInCart.Values.Sum(); |
|||
|
|||
public Category selectedCategory => this._selectedCategory; |
|||
|
|||
public float subtotalCost |
|||
{ |
|||
get |
|||
{ |
|||
var sum = 0; |
|||
foreach (var id in this.productsInCart.Keys) |
|||
sum += this._availableProducts[id].price * this.productsInCart[id]; |
|||
return sum; |
|||
} |
|||
} |
|||
|
|||
public float shippingCost => AppStateModelUtils._shippingCostPerItem * this._productsInCart.Values.Sum(); |
|||
|
|||
public float tax => this.subtotalCost * AppStateModelUtils._salesTaxRate; |
|||
|
|||
public float totalCost => this.subtotalCost + this.shippingCost + this.tax; |
|||
|
|||
|
|||
public List<Product> getProducts() |
|||
{ |
|||
if (this._availableProducts == null) return new List<Product>(); |
|||
|
|||
if (this._selectedCategory == Category.all) |
|||
return new List<Product>(this._availableProducts); |
|||
else |
|||
return this._availableProducts |
|||
.Where((Product p) => p.category == this._selectedCategory) |
|||
.ToList(); |
|||
} |
|||
|
|||
public void addProductToCart(int productId) |
|||
{ |
|||
if (!this._productsInCart.ContainsKey(productId)) |
|||
this._productsInCart[productId] = 1; |
|||
else |
|||
this._productsInCart[productId]++; |
|||
|
|||
this.notifyListeners(); |
|||
} |
|||
|
|||
public void removeItemFromCart(int productId) |
|||
{ |
|||
if (this._productsInCart.ContainsKey(productId)) |
|||
{ |
|||
if (this._productsInCart[productId] == 1) |
|||
this._productsInCart.Remove(productId); |
|||
else |
|||
this._productsInCart[productId]--; |
|||
} |
|||
|
|||
this.notifyListeners(); |
|||
} |
|||
|
|||
public Product getProductById(int id) |
|||
{ |
|||
return this._availableProducts.First((Product p) => p.id == id); |
|||
} |
|||
|
|||
public void clearCart() |
|||
{ |
|||
this._productsInCart.Clear(); |
|||
this.notifyListeners(); |
|||
} |
|||
|
|||
public void loadProducts() |
|||
{ |
|||
this._availableProducts = ProductsRepository.loadProducts(Category.all); |
|||
this.notifyListeners(); |
|||
} |
|||
|
|||
public void setCategory(Category newCategory) |
|||
{ |
|||
this._selectedCategory = newCategory; |
|||
this.notifyListeners(); |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"AppStateModel(totalCost: {this.totalCost})"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1e79c836d5b1466ea74fe5e3838c7760 |
|||
timeCreated: 1612342779 |
|
|||
using Unity.UIWidgets.foundation; |
|||
|
|||
namespace UIWidgetsGallery.demo.shrine.model |
|||
{ |
|||
public enum Category |
|||
{ |
|||
all, |
|||
accessories, |
|||
clothing, |
|||
home, |
|||
} |
|||
|
|||
public class Product |
|||
{ |
|||
public Product( |
|||
Category category, |
|||
int id, |
|||
bool isFeatured, |
|||
string name, |
|||
int price |
|||
) |
|||
{ |
|||
D.assert(name != null); |
|||
this.category = category; |
|||
this.id = id; |
|||
this.isFeatured = isFeatured; |
|||
this.name = name; |
|||
this.price = price; |
|||
} |
|||
|
|||
public readonly Category category; |
|||
public readonly int id; |
|||
public readonly bool isFeatured; |
|||
public readonly string name; |
|||
public readonly int price; |
|||
|
|||
private string assetName => $"{this.id}-0.jpg"; |
|||
private string assetPackage => "shrine_images"; |
|||
|
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{this.name} (id={this.id})"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b1cee3bedd0943a4b7c99b53520d96af |
|||
timeCreated: 1612342795 |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UIWidgetsGallery.demo.shrine.model |
|||
{ |
|||
public static class ProductsRepository |
|||
{ |
|||
public static List<Product> loadProducts(Category category) |
|||
{ |
|||
List<Product> allProducts = new List<Product> |
|||
{ |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 0, |
|||
isFeatured: true, |
|||
name: "Vagabond sack", |
|||
price: 120 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 1, |
|||
isFeatured: true, |
|||
name: "Stella sunglasses", |
|||
price: 58 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 2, |
|||
isFeatured: false, |
|||
name: "Whitney belt", |
|||
price: 35 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 3, |
|||
isFeatured: true, |
|||
name: "Garden strand", |
|||
price: 98 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 4, |
|||
isFeatured: false, |
|||
name: "Strut earrings", |
|||
price: 34 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 5, |
|||
isFeatured: false, |
|||
name: "Varsity socks", |
|||
price: 12 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 6, |
|||
isFeatured: false, |
|||
name: "Weave keyring", |
|||
price: 16 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 7, |
|||
isFeatured: true, |
|||
name: "Gatsby hat", |
|||
price: 40 |
|||
), |
|||
new Product( |
|||
category: Category.accessories, |
|||
id: 8, |
|||
isFeatured: true, |
|||
name: "Shrug bag", |
|||
price: 198 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 9, |
|||
isFeatured: true, |
|||
name: "Gilt desk trio", |
|||
price: 58 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 10, |
|||
isFeatured: false, |
|||
name: "Copper wire rack", |
|||
price: 18 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 11, |
|||
isFeatured: false, |
|||
name: "Soothe ceramic set", |
|||
price: 28 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 12, |
|||
isFeatured: false, |
|||
name: "Hurrahs tea set", |
|||
price: 34 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 13, |
|||
isFeatured: true, |
|||
name: "Blue stone mug", |
|||
price: 18 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 14, |
|||
isFeatured: true, |
|||
name: "Rainwater tray", |
|||
price: 27 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 15, |
|||
isFeatured: true, |
|||
name: "Chambray napkins", |
|||
price: 16 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 16, |
|||
isFeatured: true, |
|||
name: "Succulent planters", |
|||
price: 16 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 17, |
|||
isFeatured: false, |
|||
name: "Quartet table", |
|||
price: 175 |
|||
), |
|||
new Product( |
|||
category: Category.home, |
|||
id: 18, |
|||
isFeatured: true, |
|||
name: "Kitchen quattro", |
|||
price: 129 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 19, |
|||
isFeatured: false, |
|||
name: "Clay sweater", |
|||
price: 48 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 20, |
|||
isFeatured: false, |
|||
name: "Sea tunic", |
|||
price: 45 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 21, |
|||
isFeatured: false, |
|||
name: "Plaster tunic", |
|||
price: 38 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 22, |
|||
isFeatured: false, |
|||
name: "White pinstripe shirt", |
|||
price: 70 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 23, |
|||
isFeatured: false, |
|||
name: "Chambray shirt", |
|||
price: 70 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 24, |
|||
isFeatured: true, |
|||
name: "Seabreeze sweater", |
|||
price: 60 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 25, |
|||
isFeatured: false, |
|||
name: "Gentry jacket", |
|||
price: 178 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 26, |
|||
isFeatured: false, |
|||
name: "Navy trousers", |
|||
price: 74 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 27, |
|||
isFeatured: true, |
|||
name: "Walter henley (white)", |
|||
price: 38 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 28, |
|||
isFeatured: true, |
|||
name: "Surf and perf shirt", |
|||
price: 48 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 29, |
|||
isFeatured: true, |
|||
name: "Ginger scarf", |
|||
price: 98 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 30, |
|||
isFeatured: true, |
|||
name: "Ramona crossover", |
|||
price: 68 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 31, |
|||
isFeatured: false, |
|||
name: "Chambray shirt", |
|||
price: 38 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 32, |
|||
isFeatured: false, |
|||
name: "Classic white collar", |
|||
price: 58 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 33, |
|||
isFeatured: true, |
|||
name: "Cerise scallop tee", |
|||
price: 42 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 34, |
|||
isFeatured: false, |
|||
name: "Shoulder rolls tee", |
|||
price: 27 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 35, |
|||
isFeatured: false, |
|||
name: "Grey slouch tank", |
|||
price: 24 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 36, |
|||
isFeatured: false, |
|||
name: "Sunshirt dress", |
|||
price: 58 |
|||
), |
|||
new Product( |
|||
category: Category.clothing, |
|||
id: 37, |
|||
isFeatured: true, |
|||
name: "Fine lines tee", |
|||
price: 58 |
|||
), |
|||
}; |
|||
if (category == Category.all) |
|||
return allProducts; |
|||
else |
|||
return allProducts.Where((Product p) => p.category == category).ToList(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bee771cd2abb49a389131d2154c1538c |
|||
timeCreated: 1612342810 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.demo.shrine.model |
|||
{ |
|||
public abstract class Model : Listenable |
|||
{ |
|||
readonly HashSet<VoidCallback> _listeners = new HashSet<VoidCallback>(); |
|||
internal int _version = 0; |
|||
int _microtaskVersion = 0; |
|||
|
|||
public void addListener(VoidCallback listener) { |
|||
_listeners.Add(listener); |
|||
} |
|||
|
|||
public void removeListener(VoidCallback listener) { |
|||
_listeners.Remove(listener); |
|||
} |
|||
|
|||
int listenerCount => _listeners.Count; |
|||
|
|||
protected void notifyListeners() { |
|||
// We schedule a microtask to debounce multiple changes that can occur
|
|||
// all at once.
|
|||
if (_microtaskVersion == _version) { |
|||
_microtaskVersion++; |
|||
async_.scheduleMicrotask(() => { |
|||
_version++; |
|||
_microtaskVersion = _version; |
|||
|
|||
// Convert the Set to a List before executing each listener. This
|
|||
// prevents errors that can arise if a listener removes itself during
|
|||
// invocation!
|
|||
_listeners.ToList().ForEach((VoidCallback listener) => listener()); |
|||
return null; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class ScopedModel<T> : StatelessWidget where T : Model |
|||
{ |
|||
public ScopedModel(T model, Widget child) |
|||
{ |
|||
D.assert(model != null); |
|||
D.assert(child != null); |
|||
|
|||
this.model = model; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly T model; |
|||
public readonly Widget child; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new AnimatedBuilder( |
|||
animation: model, |
|||
builder: (subContext, _) => new _InheritedModel<T>(model: model, child: child) |
|||
); |
|||
} |
|||
|
|||
public static T of( |
|||
BuildContext context, |
|||
bool rebuildOnChange = false |
|||
) { |
|||
Type type = typeof(_InheritedModel<T>); |
|||
|
|||
Widget widget = rebuildOnChange |
|||
? context.inheritFromWidgetOfExactType(type) |
|||
: context.ancestorWidgetOfExactType(type); |
|||
|
|||
if (widget == null) { |
|||
throw new ScopedModelError(); |
|||
} else { |
|||
return (widget as _InheritedModel<T>).model; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class _InheritedModel<T> : InheritedWidget where T : Model |
|||
{ |
|||
public readonly T model; |
|||
public readonly int version; |
|||
|
|||
public _InheritedModel(Key key = null, Widget child = null, T model = null) : |
|||
base(key: key, child: child) |
|||
{ |
|||
this.model = model; |
|||
this.version = model._version; |
|||
} |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget oldWidget) |
|||
{ |
|||
var _oldWidget = (_InheritedModel<T>) oldWidget; |
|||
return _oldWidget.version != version; |
|||
} |
|||
} |
|||
|
|||
public delegate Widget ScopedModelDescendantBuilder<T>( |
|||
BuildContext context, |
|||
Widget child, |
|||
T model) where T : Model; |
|||
|
|||
public class ScopedModelDescendant<T> : StatelessWidget where T : Model |
|||
{ |
|||
public readonly ScopedModelDescendantBuilder<T> builder; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public readonly bool rebuildOnChange; |
|||
|
|||
public ScopedModelDescendant( |
|||
ScopedModelDescendantBuilder<T> builder = null, |
|||
Widget child = null, |
|||
bool rebuildOnChange = true) |
|||
{ |
|||
D.assert(builder != null); |
|||
this.builder = builder; |
|||
this.child = child; |
|||
this.rebuildOnChange = rebuildOnChange; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return builder( |
|||
context, |
|||
child, |
|||
ScopedModel<T>.of(context, rebuildOnChange: rebuildOnChange) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class ScopedModelError : UIWidgetsError |
|||
{ |
|||
public ScopedModelError() : base("") |
|||
{ |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return "Error: Could not find the correct ScopedModel."; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5aecacaf37684830a0325ef44da51137 |
|||
timeCreated: 1612343339 |
|
|||
fileFormatVersion: 2 |
|||
guid: d4ae99a1fe134a4581fd4dad88a477f7 |
|||
timeCreated: 1612342758 |
|
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public static class GalleryAboutUtils |
|||
{ |
|||
public static void showGalleryAboutDialog(BuildContext context) |
|||
{ |
|||
ThemeData themeData = Theme.of(context); |
|||
TextStyle aboutTextStyle = themeData.textTheme.bodyText1; |
|||
TextStyle linkStyle = themeData.textTheme.bodyText1.copyWith(color: themeData.accentColor); |
|||
|
|||
material_.showAboutDialog( |
|||
context: context, |
|||
applicationVersion: "January 2021", |
|||
children: new List<Widget> |
|||
{ |
|||
new Padding( |
|||
padding: EdgeInsets.only(top: 24.0f), |
|||
child: new RichText( |
|||
text: new TextSpan( |
|||
children: new List<InlineSpan> |
|||
{ |
|||
new TextSpan( |
|||
style: aboutTextStyle, |
|||
text: "uiwidgets is an open-source project to help developers " + |
|||
"build high-performance, high-fidelity, mobile apps for multiple platforms using " + |
|||
"Unity Editor" + |
|||
"from a single codebase. This design lab is a playground " + |
|||
"and showcase of Flutter's many widgets, behaviors, " + |
|||
"animations, layouts, and more. Learn more about Flutter at " |
|||
), |
|||
new _LinkTextSpan( |
|||
style: linkStyle, |
|||
url: "https://github.com/Unity-Technologies/com.unity.uiwidgets", |
|||
text: "uiWidgets github repo" |
|||
), |
|||
new TextSpan( |
|||
style: aboutTextStyle, |
|||
text: "." |
|||
) |
|||
} |
|||
) |
|||
) |
|||
) |
|||
} |
|||
); |
|||
} |
|||
} |
|||
public class _LinkTextSpan : TextSpan |
|||
{ |
|||
private static void launch(string url) |
|||
{ |
|||
Process.Start(url); |
|||
} |
|||
|
|||
public _LinkTextSpan(TextStyle style = null, string url = null, string text = null) : base( |
|||
style: style, |
|||
text: text ?? url, |
|||
recognizer: new TapGestureRecognizer {onTap = () => { launch(url); }} |
|||
) |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d167035ecc19482a9586a95d0a562503 |
|||
timeCreated: 1612322610 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public static class GalleryBackdropUtils |
|||
{ |
|||
public const float _kFrontHeadingHeight = 32.0f; // front layer beveled rectangle
|
|||
public const float _kFrontClosedHeight = 92.0f; // front layer height when closed
|
|||
public const float _kBackAppBarHeight = 56.0f; // back layer (options) appbar height
|
|||
|
|||
public static readonly Animatable<BorderRadius> _kFrontHeadingBevelRadius = new BorderRadiusTween( |
|||
begin: BorderRadius.only( |
|||
topLeft: Radius.circular(12.0f), |
|||
topRight: Radius.circular(12.0f) |
|||
), |
|||
end: BorderRadius.only( |
|||
topLeft: Radius.circular(_kFrontHeadingHeight), |
|||
topRight: Radius.circular(_kFrontHeadingHeight) |
|||
) |
|||
); |
|||
} |
|||
|
|||
internal class _TappableWhileStatusIs : StatefulWidget |
|||
{ |
|||
public _TappableWhileStatusIs( |
|||
AnimationStatus status, |
|||
Key key = null, |
|||
AnimationController controller = null, |
|||
Widget child = null |
|||
) : base(key: key) |
|||
{ |
|||
this.controller = controller; |
|||
this.status = status; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly AnimationController controller; |
|||
public readonly AnimationStatus status; |
|||
public readonly Widget child; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _TappableWhileStatusIsState(); |
|||
} |
|||
} |
|||
|
|||
internal class _TappableWhileStatusIsState : State<_TappableWhileStatusIs> |
|||
{ |
|||
private bool _active; |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this.widget.controller.addStatusListener(this._handleStatusChange); |
|||
this._active = this.widget.controller.status == this.widget.status; |
|||
} |
|||
|
|||
|
|||
public override void dispose() |
|||
{ |
|||
this.widget.controller.removeStatusListener(this._handleStatusChange); |
|||
base.dispose(); |
|||
} |
|||
|
|||
private void _handleStatusChange(AnimationStatus status) |
|||
{ |
|||
bool value = this.widget.controller.status == this.widget.status; |
|||
if (this._active != value) |
|||
this.setState(() => { this._active = value; }); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
Widget child = new AbsorbPointer( |
|||
absorbing: !this._active, |
|||
child: this.widget.child |
|||
); |
|||
|
|||
if (!this._active) |
|||
child = new FocusScope( |
|||
canRequestFocus: false, |
|||
debugLabel: "_TappableWhileStatusIs", |
|||
child: child |
|||
); |
|||
|
|||
return child; |
|||
} |
|||
} |
|||
|
|||
internal class _CrossFadeTransition : AnimatedWidget |
|||
{ |
|||
public _CrossFadeTransition( |
|||
Key key = null, |
|||
Alignment alignment = null, |
|||
Animation<float> progress = null, |
|||
Widget child0 = null, |
|||
Widget child1 = null |
|||
) : base(key: key, listenable: progress) |
|||
{ |
|||
alignment = alignment ?? Alignment.center; |
|||
this.alignment = alignment; |
|||
this.child0 = child0; |
|||
this.child1 = child1; |
|||
} |
|||
|
|||
public readonly Alignment alignment; |
|||
public readonly Widget child0; |
|||
public readonly Widget child1; |
|||
|
|||
|
|||
protected override Widget build(BuildContext context) |
|||
{ |
|||
Animation<float> progress = this.listenable as Animation<float>; |
|||
|
|||
float opacity1 = new CurvedAnimation( |
|||
parent: new ReverseAnimation(progress), |
|||
curve: new Interval(0.5f, 1.0f) |
|||
).value; |
|||
|
|||
float opacity2 = new CurvedAnimation( |
|||
parent: progress, |
|||
curve: new Interval(0.5f, 1.0f) |
|||
).value; |
|||
|
|||
return new Stack( |
|||
alignment: this.alignment, |
|||
children: new List<Widget> |
|||
{ |
|||
new Opacity( |
|||
opacity: opacity1, |
|||
child: this.child1 |
|||
), |
|||
new Opacity( |
|||
opacity: opacity2, |
|||
child: this.child0 |
|||
) |
|||
} |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _BackAppBar : StatelessWidget |
|||
{ |
|||
public _BackAppBar( |
|||
Key key = null, |
|||
Widget leading = null, |
|||
Widget title = null, |
|||
Widget trailing = null |
|||
) : base(key: key) |
|||
{ |
|||
leading = leading ?? new SizedBox(width: 56.0f); |
|||
D.assert(title != null); |
|||
this.leading = leading; |
|||
this.title = title; |
|||
this.trailing = trailing; |
|||
} |
|||
|
|||
public readonly Widget leading; |
|||
public readonly Widget title; |
|||
public readonly Widget trailing; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
ThemeData theme = Theme.of(context); |
|||
|
|||
List<Widget> children = new List<Widget> |
|||
{ |
|||
new Container( |
|||
alignment: Alignment.center, |
|||
width: 56.0f, |
|||
child: this.leading |
|||
), |
|||
new Expanded( |
|||
child: this.title |
|||
) |
|||
}; |
|||
|
|||
if (this.trailing != null) |
|||
children.Add(new Container( |
|||
alignment: Alignment.center, |
|||
width: 56.0f, |
|||
child: this.trailing |
|||
)); |
|||
|
|||
return IconTheme.merge( |
|||
data: theme.primaryIconTheme, |
|||
child: new DefaultTextStyle( |
|||
style: theme.primaryTextTheme.headline6, |
|||
child: new SizedBox( |
|||
height: GalleryBackdropUtils._kBackAppBarHeight, |
|||
child: new Row( |
|||
children: children |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class Backdrop : StatefulWidget |
|||
{ |
|||
public Backdrop( |
|||
Widget frontAction = null, |
|||
Widget frontTitle = null, |
|||
Widget frontLayer = null, |
|||
Widget frontHeading = null, |
|||
Widget backTitle = null, |
|||
Widget backLayer = null |
|||
) |
|||
{ |
|||
this.frontAction = frontAction; |
|||
this.frontTitle = frontTitle; |
|||
this.frontLayer = frontLayer; |
|||
this.frontHeading = frontHeading; |
|||
this.backTitle = backTitle; |
|||
this.backLayer = backLayer; |
|||
} |
|||
|
|||
public readonly Widget frontAction; |
|||
public readonly Widget frontTitle; |
|||
public readonly Widget frontLayer; |
|||
public readonly Widget frontHeading; |
|||
public readonly Widget backTitle; |
|||
public readonly Widget backLayer; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _BackdropState(); |
|||
} |
|||
} |
|||
|
|||
internal class _BackdropState : SingleTickerProviderStateMixin<Backdrop> |
|||
{ |
|||
private GlobalKey _backdropKey = GlobalKey.key(debugLabel: "Backdrop"); |
|||
private AnimationController _controller; |
|||
private Animation<float> _frontOpacity; |
|||
|
|||
private static readonly Animatable<float> _frontOpacityTween = new Tween<float>(begin: 0.2f, end: 1.0f) |
|||
.chain(new CurveTween(curve: new Interval(0.0f, 0.4f, curve: Curves.easeInOut))); |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._controller = new AnimationController( |
|||
duration: new TimeSpan(0, 0, 0, 0, 300), |
|||
value: 1.0f, |
|||
vsync: this |
|||
); |
|||
this._frontOpacity = this._controller.drive(_frontOpacityTween); |
|||
} |
|||
|
|||
public override void dispose() |
|||
{ |
|||
this._controller.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
private float _backdropHeight |
|||
{ |
|||
get |
|||
{ |
|||
// Warning: this can be safely called from the event handlers but it may
|
|||
// not be called at build time.
|
|||
RenderBox renderBox = this._backdropKey.currentContext.findRenderObject() as RenderBox; |
|||
return Mathf.Max(0.0f, |
|||
renderBox.size.height - GalleryBackdropUtils._kBackAppBarHeight - |
|||
GalleryBackdropUtils._kFrontClosedHeight); |
|||
} |
|||
} |
|||
|
|||
private void _handleDragUpdate(DragUpdateDetails details) |
|||
{ |
|||
this._controller.setValue(this._controller.value - details.primaryDelta.Value / this._backdropHeight); |
|||
} |
|||
|
|||
private void _handleDragEnd(DragEndDetails details) |
|||
{ |
|||
if (this._controller.isAnimating || this._controller.status == AnimationStatus.completed) |
|||
return; |
|||
|
|||
float flingVelocity = details.velocity.pixelsPerSecond.dy / this._backdropHeight; |
|||
if (flingVelocity < 0.0) |
|||
this._controller.fling(velocity: Mathf.Max(2.0f, -flingVelocity)); |
|||
else if (flingVelocity > 0.0) |
|||
this._controller.fling(velocity: Mathf.Min(-2.0f, -flingVelocity)); |
|||
else |
|||
this._controller.fling(velocity: this._controller.value < 0.5 ? -2.0f : 2.0f); |
|||
} |
|||
|
|||
private void _toggleFrontLayer() |
|||
{ |
|||
AnimationStatus status = this._controller.status; |
|||
bool isOpen = status == AnimationStatus.completed || status == AnimationStatus.forward; |
|||
this._controller.fling(velocity: isOpen ? -2.0f : 2.0f); |
|||
} |
|||
|
|||
private Widget _buildStack(BuildContext context, BoxConstraints constraints) |
|||
{ |
|||
Animation<RelativeRect> frontRelativeRect = this._controller.drive(new RelativeRectTween( |
|||
begin: RelativeRect.fromLTRB(0.0f, |
|||
constraints.biggest.height - GalleryBackdropUtils._kFrontClosedHeight, 0.0f, 0.0f), |
|||
end: RelativeRect.fromLTRB(0.0f, GalleryBackdropUtils._kBackAppBarHeight, 0.0f, 0.0f) |
|||
)); |
|||
|
|||
var children = new List<Widget> |
|||
{ |
|||
new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: new List<Widget> |
|||
{ |
|||
new _BackAppBar( |
|||
leading: this.widget.frontAction, |
|||
title: new _CrossFadeTransition( |
|||
progress: this._controller, |
|||
alignment: Alignment.center, |
|||
//alignment: AlignmentDirectional.centerStart,
|
|||
child0: this.widget.frontTitle, |
|||
child1: this.widget.backTitle |
|||
), |
|||
trailing: new IconButton( |
|||
onPressed: this._toggleFrontLayer, |
|||
tooltip: "Toggle options page", |
|||
icon: new AnimatedIcon( |
|||
icon: AnimatedIcons.close_menu, |
|||
progress: this._controller |
|||
) |
|||
) |
|||
), |
|||
new Expanded( |
|||
child: new _TappableWhileStatusIs( |
|||
AnimationStatus.dismissed, |
|||
controller: this._controller, |
|||
child: new Visibility( |
|||
child: this.widget.backLayer, |
|||
visible: this._controller.status != AnimationStatus.completed, |
|||
maintainState: true |
|||
) |
|||
) |
|||
) |
|||
} |
|||
), |
|||
// Front layer
|
|||
new PositionedTransition( |
|||
rect: frontRelativeRect, |
|||
child: new AnimatedBuilder( |
|||
animation: this._controller, |
|||
builder: (BuildContext subContext, Widget child) => |
|||
{ |
|||
return new PhysicalShape( |
|||
elevation: 12.0f, |
|||
color: Theme.of(subContext).canvasColor, |
|||
clipper: new ShapeBorderClipper( |
|||
shape: new BeveledRectangleBorder( |
|||
borderRadius: GalleryBackdropUtils._kFrontHeadingBevelRadius.transform( |
|||
this._controller.value) |
|||
) |
|||
), |
|||
clipBehavior: Clip.antiAlias, |
|||
child: child |
|||
); |
|||
}, |
|||
child: new _TappableWhileStatusIs( |
|||
AnimationStatus.completed, |
|||
controller: this._controller, |
|||
child: new FadeTransition( |
|||
opacity: this._frontOpacity, |
|||
child: this.widget.frontLayer |
|||
) |
|||
) |
|||
) |
|||
) |
|||
}; |
|||
|
|||
if (this.widget.frontHeading != null) |
|||
children.Add(new PositionedTransition( |
|||
rect: frontRelativeRect, |
|||
child: new Container( |
|||
alignment: Alignment.topLeft, |
|||
child: new GestureDetector( |
|||
behavior: HitTestBehavior.opaque, |
|||
onTap: this._toggleFrontLayer, |
|||
onVerticalDragUpdate: this._handleDragUpdate, |
|||
onVerticalDragEnd: this._handleDragEnd, |
|||
child: this.widget.frontHeading |
|||
) |
|||
) |
|||
)); |
|||
|
|||
return new Stack( |
|||
key: this._backdropKey, |
|||
children: children |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new LayoutBuilder(builder: this._buildStack); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a1683ac7e52d43c2b016d6f38ee988ad |
|||
timeCreated: 1612334782 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public class GalleryDemoCategory |
|||
{ |
|||
public GalleryDemoCategory( |
|||
string name, |
|||
IconData icon) |
|||
{ |
|||
this.name = name; |
|||
this.icon = icon; |
|||
} |
|||
|
|||
public readonly string name; |
|||
public readonly IconData icon; |
|||
|
|||
public bool Equals(GalleryDemoCategory other) |
|||
{ |
|||
if (ReferenceEquals(this, other)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(other, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return this.icon.Equals(other.icon) && this.name == other.name; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (ReferenceEquals(this, obj)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(obj, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (obj.GetType() != GetType()) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return Equals((GalleryDemoCategory)obj); |
|||
} |
|||
|
|||
public static bool operator==(GalleryDemoCategory left, GalleryDemoCategory right) |
|||
{ |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(GalleryDemoCategory left, GalleryDemoCategory right) |
|||
{ |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return ((icon?.GetHashCode() ?? 0) * 397) ^ (name?.GetHashCode() ?? 0); |
|||
} |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{GetType()}{name}"; |
|||
} |
|||
|
|||
public static readonly GalleryDemoCategory _kDemos = new GalleryDemoCategory( |
|||
name: "Studies", |
|||
icon: GalleryIcons.animation |
|||
); |
|||
|
|||
public static readonly GalleryDemoCategory _kStyle = new GalleryDemoCategory( |
|||
name: "Style", |
|||
icon: GalleryIcons.custom_typography |
|||
); |
|||
|
|||
public static readonly GalleryDemoCategory _kMaterialComponents = new GalleryDemoCategory( |
|||
name: "Material", |
|||
icon: GalleryIcons.category_mdc |
|||
); |
|||
|
|||
public static readonly GalleryDemoCategory _kCupertinoComponents = new GalleryDemoCategory( |
|||
name: "Cupertino", |
|||
icon: GalleryIcons.phone_iphone |
|||
); |
|||
|
|||
public static readonly GalleryDemoCategory _kMedia = new GalleryDemoCategory( |
|||
name: "Media", |
|||
icon: GalleryIcons.drive_video |
|||
); |
|||
} |
|||
|
|||
class GalleryDemo { |
|||
public GalleryDemo( |
|||
string title = null, |
|||
IconData icon = null, |
|||
string subtitle = null, |
|||
GalleryDemoCategory category = null, |
|||
string routeName = null, |
|||
string documentationUrl = null, |
|||
WidgetBuilder buildRoute = null |
|||
) |
|||
{ |
|||
D.assert(title != null); |
|||
D.assert(category != null); |
|||
D.assert(routeName != null); |
|||
D.assert(buildRoute != null); |
|||
|
|||
this.title = title; |
|||
this.icon = icon; |
|||
this.subtitle = subtitle; |
|||
this.category = category; |
|||
this.routeName = routeName; |
|||
this.documentationUrl = documentationUrl; |
|||
this.buildRoute = buildRoute; |
|||
} |
|||
|
|||
public readonly string title; |
|||
public readonly IconData icon; |
|||
public readonly string subtitle; |
|||
public readonly GalleryDemoCategory category; |
|||
public readonly string routeName; |
|||
public readonly WidgetBuilder buildRoute; |
|||
public readonly string documentationUrl; |
|||
|
|||
public override string ToString() { |
|||
return $"{GetType()}({title} {routeName})"; |
|||
} |
|||
|
|||
public static List<GalleryDemo> _buildGalleryDemos() |
|||
{ |
|||
List<GalleryDemo> galleryDemos = new List<GalleryDemo> |
|||
{ |
|||
|
|||
}; |
|||
|
|||
return galleryDemos; |
|||
} |
|||
|
|||
public static readonly List<GalleryDemo> kAllGalleryDemos = _buildGalleryDemos(); |
|||
|
|||
public static readonly List<GalleryDemoCategory> kAllGalleryDemoCategories = |
|||
kAllGalleryDemos.Select<GalleryDemo, GalleryDemoCategory>((GalleryDemo demo) => demo.category).ToList(); |
|||
|
|||
|
|||
static Dictionary<GalleryDemoCategory, List<GalleryDemo>> _generateCategoryToDemos() |
|||
{ |
|||
Dictionary<GalleryDemoCategory, List<GalleryDemo>> result = |
|||
new Dictionary<GalleryDemoCategory, List<GalleryDemo>>(); |
|||
|
|||
foreach (var category in kAllGalleryDemoCategories) |
|||
{ |
|||
result.Add(category, kAllGalleryDemos.Where((GalleryDemo demo) => |
|||
{ |
|||
return demo.category == category; |
|||
}).ToList()); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public static readonly Dictionary<GalleryDemoCategory, List<GalleryDemo>> kGalleryCategoryToDemos = |
|||
_generateCategoryToDemos(); |
|||
|
|||
static Dictionary<string, string> _generateDemoDocumentationUrls() |
|||
{ |
|||
Dictionary<string, string> result = new Dictionary<string, string>(); |
|||
|
|||
foreach (var demo in kAllGalleryDemos) |
|||
{ |
|||
if (demo.documentationUrl != null) |
|||
{ |
|||
result.Add(demo.routeName, demo.documentationUrl); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public static readonly Dictionary<string, string> kDemoDocumentationUrl = _generateDemoDocumentationUrls(); |
|||
} |
|||
|
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: beaf8ef32d5a4e4b847b0626276b30ca |
|||
timeCreated: 1612337523 |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c8e2b6d71b743648d57a549e2b0c62e |
|||
timeCreated: 1612338820 |
|
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public static class GalleryIcons |
|||
{ |
|||
public static readonly IconData tooltip = new IconData(0xe900, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData text_fields_alt = new IconData(0xe901, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData tabs = new IconData(0xe902, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData switches = new IconData(0xe903, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData sliders = new IconData(0xe904, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData shrine = new IconData(0xe905, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData sentiment_very_satisfied = new IconData(0xe906, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData refresh = new IconData(0xe907, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData progress_activity = new IconData(0xe908, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData phone_iphone = new IconData(0xe909, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData page_control = new IconData(0xe90a, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData more_vert = new IconData(0xe90b, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData menu = new IconData(0xe90c, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData list_alt = new IconData(0xe90d, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData grid_on = new IconData(0xe90e, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData expand_all = new IconData(0xe90f, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData events = new IconData(0xe910, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData drive_video = new IconData(0xe911, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData dialogs = new IconData(0xe912, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData data_table = new IconData(0xe913, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData custom_typography = new IconData(0xe914, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData colors = new IconData(0xe915, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData chips = new IconData(0xe916, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData check_box = new IconData(0xe917, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData cards = new IconData(0xe918, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData buttons = new IconData(0xe919, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData bottom_sheets = new IconData(0xe91a, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData bottom_navigation = new IconData(0xe91b, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData animation = new IconData(0xe91c, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData account_box = new IconData(0xe91d, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData snackbar = new IconData(0xe91e, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData category_mdc = new IconData(0xe91f, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData cupertino_progress = new IconData(0xe920, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData cupertino_pull_to_refresh = new IconData(0xe921, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData cupertino_switch = new IconData(0xe922, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData generic_buttons = new IconData(0xe923, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData backdrop = new IconData(0xe924, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData bottom_app_bar = new IconData(0xe925, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData bottom_sheet_persistent = new IconData(0xe926, fontFamily: "GalleryIcons"); |
|||
public static readonly IconData lists_leave_behind = new IconData(0xe927, fontFamily: "GalleryIcons"); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 77d0b3e255db46828d85f61b587bcb43 |
|||
timeCreated: 1612324774 |
|
|||
fileFormatVersion: 2 |
|||
guid: 73fb5821ecc441269db224976d575666 |
|||
timeCreated: 1612324913 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.material; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public class GalleryTextScaleValue : IEquatable<GalleryTextScaleValue> |
|||
{ |
|||
public GalleryTextScaleValue(float? scale, string label) |
|||
{ |
|||
this.scale = scale; |
|||
this.label = label; |
|||
} |
|||
|
|||
public readonly float? scale; |
|||
public readonly string label; |
|||
|
|||
|
|||
public bool Equals(GalleryTextScaleValue other) |
|||
{ |
|||
if (ReferenceEquals(this, other)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(other, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return this.scale.Equals(other.scale) && this.label == other.label; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (ReferenceEquals(this, obj)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(obj, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (obj.GetType() != GetType()) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return Equals((GalleryTextScaleValue)obj); |
|||
} |
|||
|
|||
public static bool operator==(GalleryTextScaleValue left, GalleryTextScaleValue right) |
|||
{ |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(GalleryTextScaleValue left, GalleryTextScaleValue right) |
|||
{ |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return ((label?.GetHashCode() ?? 0) * 397) ^ (scale?.GetHashCode() ?? 0); |
|||
} |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{GetType()}{label}"; |
|||
} |
|||
|
|||
public static readonly List<GalleryTextScaleValue> kAllGalleryTextScaleValues = new List<GalleryTextScaleValue>{ |
|||
new GalleryTextScaleValue(null, "System Default"), |
|||
new GalleryTextScaleValue(0.8f, "Small"), |
|||
new GalleryTextScaleValue(1.0f, "Normal"), |
|||
new GalleryTextScaleValue(1.3f, "Large"), |
|||
new GalleryTextScaleValue(2.0f, "Huge"), |
|||
}; |
|||
} |
|||
|
|||
public class GalleryVisualDensityValue : IEquatable<GalleryVisualDensityValue> |
|||
{ |
|||
public GalleryVisualDensityValue(VisualDensity visualDensity, string label) |
|||
{ |
|||
this.visualDensity = visualDensity; |
|||
this.label = label; |
|||
} |
|||
|
|||
public readonly VisualDensity visualDensity; |
|||
public readonly string label; |
|||
|
|||
public bool Equals(GalleryVisualDensityValue other) |
|||
{ |
|||
if (ReferenceEquals(this, other)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(other, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return this.visualDensity.Equals(other.visualDensity) && this.label == other.label; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (ReferenceEquals(this, obj)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (ReferenceEquals(obj, null)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (obj.GetType() != GetType()) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return Equals((GalleryVisualDensityValue)obj); |
|||
} |
|||
|
|||
public static bool operator==(GalleryVisualDensityValue left, GalleryVisualDensityValue right) |
|||
{ |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(GalleryVisualDensityValue left, GalleryVisualDensityValue right) |
|||
{ |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return ((label?.GetHashCode() ?? 0) * 397) ^ (visualDensity?.GetHashCode() ?? 0); |
|||
} |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{GetType()}{label}"; |
|||
} |
|||
|
|||
public static readonly List<GalleryVisualDensityValue> kAllGalleryVisualDensityValues = new List<GalleryVisualDensityValue>{ |
|||
new GalleryVisualDensityValue(new VisualDensity(), "System Default"), |
|||
new GalleryVisualDensityValue(VisualDensity.comfortable, "Comfortable"), |
|||
new GalleryVisualDensityValue(VisualDensity.compact, "Compact"), |
|||
new GalleryVisualDensityValue(new VisualDensity(horizontal: -3, vertical: -3), "Very Compact") |
|||
}; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 536d205536f347459208349c7fb5220c |
|||
timeCreated: 1612324936 |
|
|||
using uiwidgets; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public static class GalleyThemes |
|||
{ |
|||
public static readonly ThemeData kLightGalleryTheme = _buildLightTheme(); |
|||
public static readonly ThemeData kDarkGalleryTheme = _buildDarkTheme(); |
|||
|
|||
private static string _defaultGalleryFontFamily = ""; |
|||
|
|||
private static TextTheme _buildTextTheme(TextTheme baseTheme) |
|||
{ |
|||
if (_defaultGalleryFontFamily != "") |
|||
return baseTheme.copyWith( |
|||
headline6: baseTheme.headline6.copyWith( |
|||
fontFamily: _defaultGalleryFontFamily |
|||
) |
|||
); |
|||
|
|||
return baseTheme; |
|||
} |
|||
|
|||
private static ThemeData _buildDarkTheme() |
|||
{ |
|||
Color primaryColor = new Color(0xFF0175c2); |
|||
Color secondaryColor = new Color(0xFF13B9FD); |
|||
ColorScheme colorScheme = ColorScheme.dark().copyWith( |
|||
primary: primaryColor, |
|||
secondary: secondaryColor |
|||
); |
|||
ThemeData baseTheme = new ThemeData( |
|||
brightness: Brightness.dark, |
|||
accentColorBrightness: Brightness.dark, |
|||
primaryColor: primaryColor, |
|||
primaryColorDark: new Color(0xFF0050a0), |
|||
primaryColorLight: secondaryColor, |
|||
buttonColor: primaryColor, |
|||
indicatorColor: Colors.white, |
|||
toggleableActiveColor: new Color(0xFF6997DF), |
|||
accentColor: secondaryColor, |
|||
canvasColor: new Color(0xFF202124), |
|||
scaffoldBackgroundColor: new Color(0xFF202124), |
|||
backgroundColor: new Color(0xFF202124), |
|||
errorColor: new Color(0xFFB00020), |
|||
buttonTheme: new ButtonThemeData( |
|||
colorScheme: colorScheme, |
|||
textTheme: ButtonTextTheme.primary |
|||
) |
|||
); |
|||
return baseTheme.copyWith( |
|||
textTheme: _buildTextTheme(baseTheme.textTheme), |
|||
primaryTextTheme: _buildTextTheme(baseTheme.primaryTextTheme), |
|||
accentTextTheme: _buildTextTheme(baseTheme.accentTextTheme) |
|||
); |
|||
} |
|||
|
|||
private static ThemeData _buildLightTheme() |
|||
{ |
|||
Color primaryColor = new Color(0xFF0175c2); |
|||
Color secondaryColor = new Color(0xFF13B9FD); |
|||
ColorScheme colorScheme = ColorScheme.light().copyWith( |
|||
primary: primaryColor, |
|||
secondary: secondaryColor |
|||
); |
|||
ThemeData baseTheme = new ThemeData( |
|||
brightness: Brightness.light, |
|||
accentColorBrightness: Brightness.dark, |
|||
colorScheme: colorScheme, |
|||
primaryColor: primaryColor, |
|||
buttonColor: primaryColor, |
|||
indicatorColor: Colors.white, |
|||
toggleableActiveColor: new Color(0xFF1E88E5), |
|||
splashColor: Colors.white24, |
|||
splashFactory: InkRipple.splashFactory, |
|||
accentColor: secondaryColor, |
|||
canvasColor: Colors.white, |
|||
scaffoldBackgroundColor: Colors.white, |
|||
backgroundColor: Colors.white, |
|||
errorColor: new Color(0xFFB00020), |
|||
buttonTheme: new ButtonThemeData( |
|||
colorScheme: colorScheme, |
|||
textTheme: ButtonTextTheme.primary |
|||
) |
|||
); |
|||
return baseTheme.copyWith( |
|||
textTheme: _buildTextTheme(baseTheme.textTheme), |
|||
primaryTextTheme: _buildTextTheme(baseTheme.primaryTextTheme), |
|||
accentTextTheme: _buildTextTheme(baseTheme.accentTextTheme) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3941efd4d8554df2a6f53ad10cc6ca56 |
|||
timeCreated: 1612324365 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public delegate Future<string> UpdateUrlFetcher(); |
|||
|
|||
internal class Updater : StatefulWidget |
|||
{ |
|||
public Updater(UpdateUrlFetcher updateUrlFetcher, Widget child = null, Key key = null) |
|||
: |
|||
base(key: key) |
|||
{ |
|||
D.assert(updateUrlFetcher != null); |
|||
this.child = child; |
|||
this.updateUrlFetcher = updateUrlFetcher; |
|||
} |
|||
|
|||
public readonly UpdateUrlFetcher updateUrlFetcher; |
|||
public readonly Widget child; |
|||
|
|||
|
|||
public override State createState() |
|||
{ |
|||
return new UpdaterState(); |
|||
} |
|||
} |
|||
|
|||
|
|||
internal class UpdaterState : State<Updater> |
|||
{ |
|||
private static void launch(string url) |
|||
{ |
|||
Process.Start(url); |
|||
} |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._checkForUpdates(); |
|||
} |
|||
|
|||
private static DateTime _lastUpdateCheck; |
|||
|
|||
private void _checkForUpdates() |
|||
{ |
|||
// Only prompt once a day
|
|||
if (_lastUpdateCheck != null && |
|||
DateTime.Now - _lastUpdateCheck < new TimeSpan(1, 0, 0, 0)) |
|||
return; // We already checked for updates recently
|
|||
_lastUpdateCheck = DateTime.Now; |
|||
this.widget.updateUrlFetcher.Invoke().then(updateUrl => |
|||
{ |
|||
if (updateUrl != null) |
|||
material_.showDialog<bool>(context: this.context, builder: this._buildDialog).then(wantsUpdate => |
|||
{ |
|||
if (wantsUpdate != null && (bool) wantsUpdate) |
|||
launch((string) updateUrl); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
private Widget _buildDialog(BuildContext context) |
|||
{ |
|||
ThemeData theme = Theme.of(context); |
|||
TextStyle dialogTextStyle = |
|||
theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color); |
|||
return new AlertDialog( |
|||
title: new Text("Update UIWidgets Gallery?"), |
|||
content: new Text("A newer version is available.", style: dialogTextStyle), |
|||
actions: new List<Widget> |
|||
{ |
|||
new FlatButton( |
|||
child: new Text("NO THANKS"), |
|||
onPressed: () => { Navigator.pop(context, false); } |
|||
), |
|||
new FlatButton( |
|||
child: new Text("UPDATE"), |
|||
onPressed: () => { Navigator.pop(context, true); } |
|||
) |
|||
} |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return this.widget.child; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 16139f3d73b447de87560f29d24aff3e |
|||
timeCreated: 1612323458 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using UIWidgetsGallery.demo.shrine.model; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.scheduler2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public class GalleryApp : StatefulWidget |
|||
{ |
|||
public GalleryApp( |
|||
Key key = null, |
|||
UpdateUrlFetcher updateUrlFetcher = null, |
|||
bool enablePerformanceOverlay = true, |
|||
bool enableRasterCacheImagesCheckerboard = true, |
|||
bool enableOffscreenLayersCheckerboard = true, |
|||
VoidCallback onSendFeedback = null, |
|||
bool testMode = false |
|||
) : base(key: key) |
|||
{ |
|||
this.updateUrlFetcher = updateUrlFetcher; |
|||
this.enablePerformanceOverlay = enablePerformanceOverlay; |
|||
this.enableRasterCacheImagesCheckerboard = enableRasterCacheImagesCheckerboard; |
|||
this.enableOffscreenLayersCheckerboard = enableOffscreenLayersCheckerboard; |
|||
this.onSendFeedback = onSendFeedback; |
|||
this.testMode = testMode; |
|||
} |
|||
|
|||
public readonly UpdateUrlFetcher updateUrlFetcher; |
|||
public readonly bool enablePerformanceOverlay; |
|||
public readonly bool enableRasterCacheImagesCheckerboard; |
|||
public readonly bool enableOffscreenLayersCheckerboard; |
|||
public readonly VoidCallback onSendFeedback; |
|||
public readonly bool testMode; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _GalleryAppState(); |
|||
} |
|||
} |
|||
|
|||
internal class _GalleryAppState : State<GalleryApp> |
|||
{ |
|||
private GalleryOptions _options; |
|||
private Timer _timeDilationTimer; |
|||
private AppStateModel model; |
|||
|
|||
private Dictionary<string, WidgetBuilder> _buildRoutes() |
|||
{ |
|||
Dictionary<string, WidgetBuilder> routeBulders = new Dictionary<string, WidgetBuilder>(); |
|||
|
|||
foreach (var demo in GalleryDemo.kAllGalleryDemos) routeBulders.Add(demo.routeName, demo.buildRoute); |
|||
|
|||
return routeBulders; |
|||
} |
|||
|
|||
private static readonly RuntimePlatform defaultTargetPlatform = RuntimePlatform.WindowsPlayer; |
|||
|
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._options = new GalleryOptions( |
|||
themeMode: ThemeMode.system, |
|||
textScaleFactor: GalleryTextScaleValue.kAllGalleryTextScaleValues[0], |
|||
visualDensity: GalleryVisualDensityValue.kAllGalleryVisualDensityValues[0], |
|||
timeDilation: scheduler_.timeDilation, |
|||
platform: defaultTargetPlatform |
|||
); |
|||
this.model = new AppStateModel(); |
|||
this.model.loadProducts(); |
|||
} |
|||
|
|||
public override void reassemble() |
|||
{ |
|||
this._options = this._options.copyWith(platform: defaultTargetPlatform); |
|||
base.reassemble(); |
|||
} |
|||
|
|||
public override void dispose() |
|||
{ |
|||
this._timeDilationTimer?.cancel(); |
|||
this._timeDilationTimer = null; |
|||
base.dispose(); |
|||
} |
|||
|
|||
private void _handleOptionsChanged(GalleryOptions newOptions) |
|||
{ |
|||
this.setState(() => |
|||
{ |
|||
if (this._options.timeDilation != newOptions.timeDilation) |
|||
{ |
|||
this._timeDilationTimer?.cancel(); |
|||
this._timeDilationTimer = null; |
|||
if (newOptions.timeDilation > 1.0f |
|||
) // We delay the time dilation change long enough that the user can see
|
|||
// that UI has started reacting and then we slam on the brakes so that
|
|||
// they see that the time is in fact now dilated.
|
|||
this._timeDilationTimer = Timer.create(new TimeSpan(0, 0, 0, 0, 150), |
|||
() => { scheduler_.timeDilation = newOptions.timeDilation; }); |
|||
else |
|||
scheduler_.timeDilation = newOptions.timeDilation; |
|||
} |
|||
|
|||
this._options = newOptions; |
|||
}); |
|||
} |
|||
|
|||
private Widget _applyTextScaleFactor(Widget child) |
|||
{ |
|||
return new Builder( |
|||
builder: (BuildContext context) => |
|||
{ |
|||
return new MediaQuery( |
|||
data: MediaQuery.of(context).copyWith( |
|||
textScaleFactor: this._options.textScaleFactor.scale |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
); |
|||
} |
|||
|
|||
private static void defaultSendFeedback() |
|||
{ |
|||
Debug.Log("hello UIWidgets !"); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
Widget home = new GalleryHome( |
|||
testMode: this.widget.testMode, |
|||
optionsPage: new GalleryOptionsPage( |
|||
options: this._options, |
|||
onOptionsChanged: this._handleOptionsChanged, |
|||
onSendFeedback: this.widget.onSendFeedback ?? defaultSendFeedback |
|||
) |
|||
); |
|||
|
|||
if (this.widget.updateUrlFetcher != null) |
|||
home = new Updater( |
|||
updateUrlFetcher: this.widget.updateUrlFetcher, |
|||
child: home |
|||
); |
|||
|
|||
return new ScopedModel<AppStateModel>( |
|||
model: this.model, |
|||
child: new MaterialApp( |
|||
theme: GalleyThemes.kLightGalleryTheme.copyWith(platform: this._options.platform, |
|||
visualDensity: this._options.visualDensity.visualDensity), |
|||
darkTheme: GalleyThemes.kDarkGalleryTheme.copyWith(platform: this._options.platform, |
|||
visualDensity: this._options.visualDensity.visualDensity), |
|||
themeMode: this._options.themeMode.Value, |
|||
title: "Flutter Gallery", |
|||
color: Colors.grey, |
|||
showPerformanceOverlay: this._options.showPerformanceOverlay, |
|||
checkerboardOffscreenLayers: this._options.showOffscreenLayersCheckerboard, |
|||
checkerboardRasterCacheImages: this._options.showRasterCacheImagesCheckerboard, |
|||
routes: this._buildRoutes(), |
|||
builder: (BuildContext subContext, Widget child) => |
|||
{ |
|||
return new Directionality( |
|||
textDirection: this._options.textDirection.Value, |
|||
child: this._applyTextScaleFactor( |
|||
// Specifically use a blank Cupertino theme here and do not transfer
|
|||
// over the Material primary color etc except the brightness to
|
|||
// showcase standard iOS looks.
|
|||
new Builder(builder: (BuildContext subsubContext) => |
|||
{ |
|||
return new CupertinoTheme( |
|||
data: new CupertinoThemeData( |
|||
brightness: Theme.of(context).brightness |
|||
), |
|||
child: child |
|||
); |
|||
}) |
|||
) |
|||
); |
|||
}, |
|||
home: home |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 63b65dbf55ef42bb81d7836bd42d60c9 |
|||
timeCreated: 1612341675 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
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 GalleryHomeUtils |
|||
{ |
|||
public static readonly string _kGalleryAssetsPackage = "uiwdigets_gallery_assets"; |
|||
public static readonly Color _kFlutterBlue = new Color(0xFF003D75); |
|||
public const float _kDemoItemHeight = 64.0f; |
|||
public static readonly TimeSpan _kFrontLayerSwitchDuration = new TimeSpan(0, 0, 0, 0, 300); |
|||
} |
|||
|
|||
internal 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; |
|||
|
|||
// This repaint boundary prevents the entire _CategoriesPage from being
|
|||
// repainted when the button's ink splash animates.
|
|||
return new RepaintBoundary( |
|||
child: new RawMaterialButton( |
|||
padding: EdgeInsets.zero, |
|||
hoverColor: theme.primaryColor.withOpacity(0.05f), |
|||
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 : GalleryHomeUtils._kFlutterBlue |
|||
) |
|||
), |
|||
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.subtitle1.copyWith( |
|||
color: isDark ? Colors.white : GalleryHomeUtils._kFlutterBlue |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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: Key.key("categories"), |
|||
child: new LayoutBuilder( |
|||
builder: (BuildContext subContext, BoxConstraints constraints) => |
|||
{ |
|||
float columnWidth = constraints.biggest.width / columnCount; |
|||
float rowHeight = Mathf.Min(225.0f, columnWidth * aspectRatio); |
|||
int rowCount = (this.categories.Count() + columnCount - 1) / columnCount; |
|||
|
|||
var children = new List<Widget>(); |
|||
|
|||
for (var i = 0; i < rowCount; i++) |
|||
{ |
|||
var rowIndex = i; |
|||
int columnCountForRow = rowIndex == rowCount - 1 |
|||
? this.categories.Count() - columnCount * Mathf.Max(0, rowCount - 1) |
|||
: columnCount; |
|||
|
|||
var subChildren = new List<Widget>(); |
|||
|
|||
for (var j = 0; j < columnCountForRow; j++) |
|||
{ |
|||
var columnIndex = j; |
|||
int index = rowIndex * columnCount + columnIndex; |
|||
GalleryDemoCategory category = categoriesList[index]; |
|||
|
|||
subChildren.Add(new SizedBox(width: columnWidth, |
|||
height: rowHeight, |
|||
child: new _CategoryItem( |
|||
category: category, |
|||
onTap: () => { this.onCategoryTap(category); } |
|||
) |
|||
)); |
|||
} |
|||
|
|||
children.Add(new Row( |
|||
children: subChildren |
|||
)); |
|||
} |
|||
|
|||
return new RepaintBoundary( |
|||
child: new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: children |
|||
) |
|||
); |
|||
})); |
|||
} |
|||
} |
|||
|
|||
internal class _DemoItem : StatelessWidget |
|||
{ |
|||
public _DemoItem(Key key = null, GalleryDemo demo = null) : base(key: key) |
|||
{ |
|||
this.demo = demo; |
|||
} |
|||
|
|||
public readonly GalleryDemo demo; |
|||
|
|||
private 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); |
|||
|
|||
var children = new List<Widget> |
|||
{ |
|||
new Text(this.demo.title, |
|||
style: theme.textTheme.subtitle1.copyWith( |
|||
color: isDark ? Colors.white : new Color(0xFF202124) |
|||
) |
|||
) |
|||
}; |
|||
|
|||
if (this.demo.subtitle != null) |
|||
children.Add(new Text(this.demo.subtitle, |
|||
style: theme.textTheme.bodyText2.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: GalleryHomeUtils._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 : GalleryHomeUtils._kFlutterBlue |
|||
) |
|||
), |
|||
new Expanded( |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: children |
|||
) |
|||
), |
|||
new SizedBox(width: 44.0f) |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _DemosPage : StatelessWidget |
|||
{ |
|||
public _DemosPage(GalleryDemoCategory category) |
|||
{ |
|||
this.category = category; |
|||
} |
|||
|
|||
public readonly GalleryDemoCategory category; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
// When overriding ListView.padding, it is necessary to manually handle
|
|||
// safe areas.
|
|||
float windowBottomPadding = MediaQuery.of(context).padding.bottom; |
|||
return new KeyedSubtree( |
|||
key: Key.key("GalleryDemoList"), // So the tests can find this ListView
|
|||
child: new ListView( |
|||
dragStartBehavior: DragStartBehavior.down, |
|||
key: Key.key(this.category.name), |
|||
padding: EdgeInsets.only(top: 8.0f, bottom: windowBottomPadding), |
|||
children: GalleryDemo.kGalleryCategoryToDemos[this.category] |
|||
.Select<GalleryDemo, Widget>((GalleryDemo demo) => { return new _DemoItem(demo: demo); }) |
|||
.ToList() |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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; |
|||
|
|||
// In checked mode our MaterialApp will show the default "debug" banner.
|
|||
// Otherwise show the "preview" banner.
|
|||
public static bool showPreviewBanner = true; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _GalleryHomeState(); |
|||
} |
|||
} |
|||
|
|||
internal class _GalleryHomeState : SingleTickerProviderStateMixin<GalleryHome> |
|||
{ |
|||
private static readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key(); |
|||
private AnimationController _controller; |
|||
private GalleryDemoCategory _category; |
|||
|
|||
private static Widget _topHomeLayout(Widget currentChild, List<Widget> previousChildren) |
|||
{ |
|||
var children = new List<Widget>(); |
|||
children.AddRange(previousChildren); |
|||
if (currentChild != null) children.Add(currentChild); |
|||
|
|||
return new Stack( |
|||
children: children, |
|||
alignment: Alignment.topCenter |
|||
); |
|||
} |
|||
|
|||
private static readonly 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 ? GalleryHomeUtils._kFlutterBlue : 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 Future.value(false).to<bool>(); |
|||
} |
|||
|
|||
return Future.value(true).to<bool>(); |
|||
}, |
|||
child: new Backdrop( |
|||
backTitle: new Text("Options"), |
|||
backLayer: this.widget.optionsPage, |
|||
frontAction: new AnimatedSwitcher( |
|||
duration: GalleryHomeUtils._kFrontLayerSwitchDuration, |
|||
switchOutCurve: switchOutCurve, |
|||
switchInCurve: switchInCurve, |
|||
child: this._category == null |
|||
? (Widget) new Container() |
|||
: new IconButton( |
|||
icon: new BackButtonIcon(), |
|||
tooltip: "Back", |
|||
onPressed: () => this.setState(() => this._category = null) |
|||
) |
|||
), |
|||
frontTitle: new AnimatedSwitcher( |
|||
duration: GalleryHomeUtils._kFrontLayerSwitchDuration, |
|||
child: this._category == null |
|||
? new Text("UIWidgets gallery") |
|||
: new Text(this._category.name) |
|||
), |
|||
frontHeading: this.widget.testMode ? null : new Container(height: 24.0f), |
|||
frontLayer: new AnimatedSwitcher( |
|||
duration: GalleryHomeUtils._kFrontLayerSwitchDuration, |
|||
switchOutCurve: switchOutCurve, |
|||
switchInCurve: switchInCurve, |
|||
layoutBuilder: centerHome ? _centerHomeLayout : _topHomeLayout, |
|||
child: this._category != null |
|||
? (Widget) new _DemosPage(this._category) |
|||
: new _CategoriesPage( |
|||
categories: GalleryDemo.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; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
|
|||
namespace UIWidgetsGallery.gallery |
|||
{ |
|||
public static class GalleryOptionUtils |
|||
{ |
|||
public const float _kItemHeight = 48.0f; |
|||
|
|||
//TODO: uncomment this when fixes on EdgeInsetsDirectional lands
|
|||
//public static readonly EdgeInsetsDirectional _kItemPadding = EdgeInsetsDirectional.only(start: 56.0f);
|
|||
public static readonly EdgeInsets _kItemPadding = EdgeInsets.only(left: 56.0f); |
|||
} |
|||
|
|||
public class GalleryOptions : IEquatable<GalleryOptions> |
|||
{ |
|||
public GalleryOptions( |
|||
ThemeMode? themeMode = null, |
|||
GalleryTextScaleValue textScaleFactor = null, |
|||
GalleryVisualDensityValue visualDensity = null, |
|||
TextDirection? textDirection = null, |
|||
float timeDilation = 1.0f, |
|||
RuntimePlatform? platform = null, |
|||
bool showOffscreenLayersCheckerboard = false, |
|||
bool showRasterCacheImagesCheckerboard = false, |
|||
bool showPerformanceOverlay = false |
|||
) |
|||
{ |
|||
textDirection = textDirection ?? TextDirection.ltr; |
|||
this.themeMode = themeMode; |
|||
this.textScaleFactor = textScaleFactor; |
|||
this.visualDensity = visualDensity; |
|||
this.textDirection = textDirection; |
|||
this.timeDilation = timeDilation; |
|||
this.platform = platform; |
|||
this.showOffscreenLayersCheckerboard = showOffscreenLayersCheckerboard; |
|||
this.showRasterCacheImagesCheckerboard = showRasterCacheImagesCheckerboard; |
|||
this.showPerformanceOverlay = showPerformanceOverlay; |
|||
} |
|||
|
|||
public readonly ThemeMode? themeMode; |
|||
public readonly GalleryTextScaleValue textScaleFactor; |
|||
public readonly GalleryVisualDensityValue visualDensity; |
|||
public readonly TextDirection? textDirection; |
|||
public readonly float timeDilation; |
|||
public readonly RuntimePlatform? platform; |
|||
public readonly bool showPerformanceOverlay; |
|||
public readonly bool showRasterCacheImagesCheckerboard; |
|||
public readonly bool showOffscreenLayersCheckerboard; |
|||
|
|||
internal GalleryOptions copyWith( |
|||
ThemeMode? themeMode = null, |
|||
GalleryTextScaleValue textScaleFactor = null, |
|||
GalleryVisualDensityValue visualDensity = null, |
|||
TextDirection? textDirection = null, |
|||
float? timeDilation = null, |
|||
RuntimePlatform? platform = null, |
|||
bool? showPerformanceOverlay = null, |
|||
bool? showRasterCacheImagesCheckerboard = null, |
|||
bool? showOffscreenLayersCheckerboard = null |
|||
) |
|||
{ |
|||
return new GalleryOptions( |
|||
themeMode: themeMode ?? this.themeMode, |
|||
textScaleFactor: textScaleFactor ?? this.textScaleFactor, |
|||
visualDensity: visualDensity ?? this.visualDensity, |
|||
textDirection: textDirection ?? this.textDirection, |
|||
timeDilation: timeDilation ?? this.timeDilation, |
|||
platform: platform ?? this.platform, |
|||
showPerformanceOverlay: showPerformanceOverlay ?? this.showPerformanceOverlay, |
|||
showOffscreenLayersCheckerboard: |
|||
showOffscreenLayersCheckerboard ?? this.showOffscreenLayersCheckerboard, |
|||
showRasterCacheImagesCheckerboard: showRasterCacheImagesCheckerboard ?? |
|||
this.showRasterCacheImagesCheckerboard |
|||
); |
|||
} |
|||
|
|||
public bool Equals(GalleryOptions other) |
|||
{ |
|||
if (ReferenceEquals(this, other)) return true; |
|||
|
|||
if (ReferenceEquals(other, null)) return false; |
|||
|
|||
return this.themeMode.Equals(other.themeMode) |
|||
&& this.textScaleFactor == other.textScaleFactor |
|||
&& this.visualDensity == other.visualDensity |
|||
&& this.textDirection == other.textDirection |
|||
&& this.platform == other.platform |
|||
&& this.showPerformanceOverlay == other.showPerformanceOverlay |
|||
&& this.showRasterCacheImagesCheckerboard == other.showRasterCacheImagesCheckerboard |
|||
&& this.showOffscreenLayersCheckerboard == other.showOffscreenLayersCheckerboard; |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (ReferenceEquals(this, obj)) return true; |
|||
|
|||
if (ReferenceEquals(obj, null)) return false; |
|||
|
|||
if (obj.GetType() != this.GetType()) return false; |
|||
|
|||
return this.Equals((GalleryOptions) obj); |
|||
} |
|||
|
|||
public static bool operator ==(GalleryOptions left, GalleryOptions right) |
|||
{ |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(GalleryOptions left, GalleryOptions right) |
|||
{ |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
unchecked |
|||
{ |
|||
var hashcode = this.themeMode?.GetHashCode() ?? 0; |
|||
hashcode = (hashcode * 397) ^ this.textScaleFactor.GetHashCode(); |
|||
hashcode = (hashcode * 397) ^ this.visualDensity.GetHashCode(); |
|||
hashcode = (hashcode * 397) ^ (this.textDirection?.GetHashCode() ?? 0); |
|||
hashcode = (hashcode * 397) ^ this.timeDilation.GetHashCode(); |
|||
hashcode = (hashcode * 397) ^ (this.platform?.GetHashCode() ?? 0); |
|||
hashcode = (hashcode * 397) ^ this.showPerformanceOverlay.GetHashCode(); |
|||
hashcode = (hashcode * 397) ^ this.showRasterCacheImagesCheckerboard.GetHashCode(); |
|||
hashcode = (hashcode * 397) ^ this.showOffscreenLayersCheckerboard.GetHashCode(); |
|||
return hashcode; |
|||
} |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{this.GetType()}{this.themeMode}"; |
|||
} |
|||
} |
|||
|
|||
internal class _OptionsItem : StatelessWidget |
|||
{ |
|||
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: GalleryOptionUtils._kItemHeight * textScaleFactor), |
|||
padding: GalleryOptionUtils._kItemPadding, |
|||
alignment: AlignmentDirectional.centerStart, |
|||
child: new DefaultTextStyle( |
|||
style: DefaultTextStyle.of(context).style, |
|||
maxLines: 2, |
|||
overflow: TextOverflow.fade, |
|||
child: new IconTheme( |
|||
data: Theme.of(context).primaryIconTheme, |
|||
child: this.child |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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 |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _FlatButton : StatelessWidget |
|||
{ |
|||
public _FlatButton(Key key = null, VoidCallback onPressed = null, Widget child = null) : base(key: key) |
|||
{ |
|||
this.child = child; |
|||
this.onPressed = onPressed; |
|||
} |
|||
|
|||
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.subtitle1, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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.headline6.copyWith( |
|||
color: theme.colorScheme.onPrimary, |
|||
fontWeight: FontWeight.w700 |
|||
), |
|||
child: new Text(this.text) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _ThemeModeItem : StatelessWidget |
|||
{ |
|||
public _ThemeModeItem(GalleryOptions options, ValueChanged<GalleryOptions> onOptionsChanged) |
|||
{ |
|||
this.options = options; |
|||
this.onOptionsChanged = onOptionsChanged; |
|||
} |
|||
|
|||
public readonly GalleryOptions options; |
|||
public readonly ValueChanged<GalleryOptions> onOptionsChanged; |
|||
|
|||
public static readonly Dictionary<ThemeMode, string> modeLabels = new Dictionary<ThemeMode, string> |
|||
{ |
|||
{ThemeMode.system, "System Default"}, |
|||
{ThemeMode.light, "Light"}, |
|||
{ThemeMode.dark, "Dark"}, |
|||
}; |
|||
|
|||
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("Theme"), |
|||
new Text( |
|||
modeLabels[this.options.themeMode.Value], |
|||
style: Theme.of(context).primaryTextTheme.bodyText2 |
|||
) |
|||
} |
|||
) |
|||
), |
|||
new PopupMenuButton<ThemeMode>( |
|||
//TODO: uncomment this when fixes on EdgeInsetsDirectional lands
|
|||
//padding: const EdgeInsetsDirectional.only(end: 16.0),
|
|||
padding: EdgeInsets.only(right: 16.0f), |
|||
icon: new Icon(Icons.arrow_drop_down), |
|||
initialValue: this.options.themeMode.Value, |
|||
itemBuilder: (BuildContext subContext) => |
|||
{ |
|||
return modeLabels.Keys.Select<ThemeMode, PopupMenuEntry<ThemeMode>>((ThemeMode mode) => |
|||
{ |
|||
return new PopupMenuItem<ThemeMode>( |
|||
value: mode, |
|||
child: new Text(modeLabels[mode]) |
|||
); |
|||
}).ToList(); |
|||
}, |
|||
onSelected: (ThemeMode mode) => |
|||
{ |
|||
this.onOptionsChanged(this.options.copyWith(themeMode: mode) |
|||
); |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _TextScaleFactorItem : StatelessWidget |
|||
{ |
|||
public _TextScaleFactorItem(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 _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.bodyText2 |
|||
) |
|||
} |
|||
) |
|||
), |
|||
new PopupMenuButton<GalleryTextScaleValue>( |
|||
//TODO: uncomment this when fixes on EdgeInsetsDirectional lands
|
|||
//padding: EdgeInsetsDirectional.only(end: 16.0f),
|
|||
padding: EdgeInsets.only(right: 16.0f), |
|||
icon: new Icon(Icons.arrow_drop_down), |
|||
itemBuilder: (BuildContext subContext) => |
|||
{ |
|||
return GalleryTextScaleValue.kAllGalleryTextScaleValues |
|||
.Select<GalleryTextScaleValue, PopupMenuEntry<GalleryTextScaleValue>>( |
|||
(GalleryTextScaleValue scaleValue) => |
|||
{ |
|||
return new PopupMenuItem<GalleryTextScaleValue>( |
|||
value: scaleValue, |
|||
child: new Text(scaleValue.label) |
|||
); |
|||
}).ToList(); |
|||
}, |
|||
onSelected: (GalleryTextScaleValue scaleValue) => |
|||
{ |
|||
this.onOptionsChanged(this.options.copyWith(textScaleFactor: scaleValue) |
|||
); |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _VisualDensityItem : StatelessWidget |
|||
{ |
|||
public _VisualDensityItem(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 _OptionsItem( |
|||
child: new Row( |
|||
children: new List<Widget> |
|||
{ |
|||
new Expanded( |
|||
child: new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: new List<Widget> |
|||
{ |
|||
new Text("Visual density"), |
|||
new Text(this.options.visualDensity.label, |
|||
style: Theme.of(context).primaryTextTheme.bodyText2 |
|||
) |
|||
} |
|||
) |
|||
), |
|||
new PopupMenuButton<GalleryVisualDensityValue>( |
|||
//TODO: uncomment this when fixes on EdgeInsetsDirectional lands
|
|||
//padding: EdgeInsetsDirectional.only(end: 16.0f),
|
|||
padding: EdgeInsets.only(right: 16.0f), |
|||
icon: new Icon(Icons.arrow_drop_down), |
|||
itemBuilder: (BuildContext subContext) => |
|||
{ |
|||
return GalleryVisualDensityValue.kAllGalleryVisualDensityValues |
|||
.Select<GalleryVisualDensityValue, PopupMenuEntry<GalleryVisualDensityValue>>( |
|||
(GalleryVisualDensityValue densityValue) => |
|||
{ |
|||
return new PopupMenuItem<GalleryVisualDensityValue>( |
|||
value: densityValue, |
|||
child: new Text(densityValue.label) |
|||
); |
|||
}).ToList(); |
|||
}, |
|||
onSelected: (GalleryVisualDensityValue densityValue) => |
|||
{ |
|||
this.onOptionsChanged(this.options.copyWith(visualDensity: densityValue) |
|||
); |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal class _TextDirectionItem : StatelessWidget |
|||
{ |
|||
public _TextDirectionItem(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( |
|||
"Force RTL", this.options.textDirection == TextDirection.rtl, |
|||
(bool? value) => |
|||
{ |
|||
this.onOptionsChanged(this.options.copyWith( |
|||
textDirection: value == true ? TextDirection.rtl : TextDirection.ltr |
|||
) |
|||
); |
|||
}, |
|||
switchKey: Key.key("text_direction") |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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") |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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; |
|||
|
|||
private string _platformLabel(RuntimePlatform? platform) |
|||
{ |
|||
return platform.ToString(); |
|||
} |
|||
|
|||
private static List<RuntimePlatform> _platforms = new List<RuntimePlatform> |
|||
{RuntimePlatform.Android, RuntimePlatform.IPhonePlayer, RuntimePlatform.WindowsPlayer}; |
|||
|
|||
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.bodyText2 |
|||
) |
|||
} |
|||
) |
|||
), |
|||
new PopupMenuButton<RuntimePlatform>( |
|||
//TODO: uncomment this when fixes on EdgeInsetsDirectional lands
|
|||
//padding: EdgeInsetsDirectional.only(end: 16.0f),
|
|||
padding: EdgeInsets.only(right: 16.0f), |
|||
icon: new Icon(Icons.arrow_drop_down), |
|||
itemBuilder: (BuildContext subContext) => |
|||
{ |
|||
return _platforms.Select<RuntimePlatform, PopupMenuEntry<RuntimePlatform>>( |
|||
(RuntimePlatform platform) => |
|||
{ |
|||
return new PopupMenuItem<RuntimePlatform>( |
|||
value: platform, |
|||
child: new Text(this._platformLabel(platform)) |
|||
); |
|||
}).ToList(); |
|||
}, |
|||
onSelected: (RuntimePlatform platform) => |
|||
{ |
|||
this.onOptionsChanged(this.options.copyWith(platform: platform) |
|||
); |
|||
} |
|||
) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
internal 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; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
ThemeData theme = Theme.of(context); |
|||
|
|||
return new DefaultTextStyle( |
|||
style: theme.primaryTextTheme.subtitle1, |
|||
child: new ListView( |
|||
padding: EdgeInsets.only(bottom: 124.0f), |
|||
children: new List<Widget> |
|||
{ |
|||
new _Heading("Display"), |
|||
new _ThemeModeItem(this.options, this.onOptionsChanged), |
|||
new _TextScaleFactorItem(this.options, this.onOptionsChanged), |
|||
new _VisualDensityItem(this.options, this.onOptionsChanged), |
|||
new _TextDirectionItem(this.options, this.onOptionsChanged), |
|||
new _TimeDilationItem(this.options, this.onOptionsChanged), |
|||
new Divider(), |
|||
new _PlatformItem(this.options, this.onOptionsChanged), |
|||
new Divider(), |
|||
new _Heading("Flutter gallery"), |
|||
new _ActionItem("About Flutter Gallery", |
|||
() => { GalleryAboutUtils.showGalleryAboutDialog(context); }), |
|||
new _ActionItem("Send feedback", this.onSendFeedback) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue