您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
255 行
9.6 KiB
255 行
9.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using uiwidgets;
|
|
using Unity.UIWidgets.cupertino;
|
|
using Unity.UIWidgets.engine;
|
|
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;
|
|
using FontStyle = Unity.UIWidgets.ui.FontStyle;
|
|
using Random = System.Random;
|
|
using Text = Unity.UIWidgets.widgets.Text;
|
|
using ui_ = Unity.UIWidgets.widgets.ui_;
|
|
using TextStyle = Unity.UIWidgets.painting.TextStyle;
|
|
|
|
namespace UIWidgetsSample
|
|
{
|
|
public class ImageFlowDemo : UIWidgetsPanel
|
|
{
|
|
protected void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
}
|
|
|
|
protected override void main()
|
|
{
|
|
ui_.runApp(new ImageFlowApp());
|
|
}
|
|
}
|
|
|
|
class ImageFlowApp : StatelessWidget
|
|
{
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
return new MaterialApp(
|
|
theme: new ThemeData(
|
|
brightness: Brightness.dark,
|
|
accentColor: Colors.cyan[600],
|
|
textTheme: new TextTheme(
|
|
headline1: new TextStyle(fontSize: 72.0f, fontWeight: FontWeight.bold),
|
|
headline6: new TextStyle(fontSize: 36.0f, fontStyle: FontStyle.italic),
|
|
bodyText2: new TextStyle(fontSize: 14.0f)
|
|
)
|
|
),
|
|
home: new Example01()
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
public static class Utils
|
|
{
|
|
internal static readonly List<StaggeredTile> _staggeredTiles = new List<StaggeredTile>
|
|
{
|
|
StaggeredTile.count(2, 2),
|
|
StaggeredTile.count(2, 1),
|
|
// StaggeredTile.count(1, 2),
|
|
// StaggeredTile.count(1, 1),
|
|
// StaggeredTile.count(2, 2),
|
|
// StaggeredTile.count(1, 2),
|
|
// StaggeredTile.count(1, 1),
|
|
// StaggeredTile.count(3, 1),
|
|
// StaggeredTile.count(1, 1),
|
|
// StaggeredTile.count(4, 1),
|
|
};
|
|
|
|
public static List<Color> colors = new List<Color>()
|
|
{
|
|
Colors.red,
|
|
Colors.amber,
|
|
Colors.cyan,
|
|
Colors.brown,
|
|
Colors.purpleAccent,
|
|
Colors.blue
|
|
};
|
|
|
|
public static List<string> lotties = new List<string>()
|
|
{
|
|
"1055-world-locations.json",
|
|
"1370-confetti.json",
|
|
"1798-check-animation.json",
|
|
"226-splashy-loader.json",
|
|
"66992-the-flying-rocket.json",
|
|
"77-im-thirsty.json",
|
|
"782-check-mark-success.json",
|
|
"91-mailsent.json",
|
|
"lottieflow-checkbox-06-000000-easey.json",
|
|
"lottieflow-cta-04-000000-easey.json",
|
|
"lottieflow-radio-07-000000-easey.json",
|
|
"lottieflow-social-networks-16-12-000000-easey.json",
|
|
"lottieflow-social-networks-16-7-000000-easey.json",
|
|
};
|
|
|
|
internal static readonly List<Widget> _tiles = new List<Widget>
|
|
{
|
|
new _Example01Tile(Colors.green, Icons.widgets, "1055-world-locations.json"),
|
|
new _Example01Tile(Colors.lightBlue, Icons.wifi, "1370-confetti.json"),
|
|
// new _Example01Tile(Colors.amber, Icons.panorama_wide_angle, "1798-check-animation.json"),
|
|
// new _Example01Tile(Colors.brown, Icons.map, "226-splashy-loader.json"),
|
|
// new _Example01Tile(Colors.deepOrange, Icons.send, "66992-the-flying-rocket.json"),
|
|
// new _Example01Tile(Colors.indigo, Icons.airline_seat_flat, "77-im-thirsty.json"),
|
|
// new _Example01Tile(Colors.red, Icons.bluetooth, "782-check-mark-success.json"),
|
|
// new _Example01Tile(Colors.pink, Icons.battery_alert, "91-mailsent.json"),
|
|
// new _Example01Tile(Colors.purple, Icons.desktop_windows, "lottieflow-checkbox-06-000000-easey.json"),
|
|
// new _Example01Tile(Colors.blue, Icons.radio, "lottieflow-cta-04-000000-easey.json"),
|
|
};
|
|
|
|
internal static Random random = new Random();
|
|
}
|
|
|
|
class Example01 : StatefulWidget
|
|
{
|
|
public override State createState()
|
|
{
|
|
return new Example01State();
|
|
}
|
|
}
|
|
|
|
class Example01State : State<Example01>
|
|
{
|
|
readonly List<StaggeredTile> _staggeredTiles = new List<StaggeredTile>
|
|
{
|
|
StaggeredTile.count(2, 2),
|
|
StaggeredTile.count(2, 1),
|
|
};
|
|
|
|
readonly List<Widget> _tiles = new List<Widget>
|
|
{
|
|
new _Example01Tile(Colors.green, Icons.widgets, "1055-world-locations.json"),
|
|
new _Example01Tile(Colors.lightBlue, Icons.wifi, "1370-confetti.json"),
|
|
};
|
|
|
|
private int count = 4;
|
|
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
Debug.Log($"o tile count {_tiles.Count}");
|
|
return new Scaffold(
|
|
appBar: new AppBar(
|
|
title: new Text("example 01")
|
|
),
|
|
body:
|
|
new Column(
|
|
children: new List<Widget>()
|
|
{
|
|
new Expanded(child:
|
|
new Container(
|
|
child:
|
|
StaggeredGridView.count(
|
|
crossAxisCount: count,
|
|
staggeredTiles: _staggeredTiles,
|
|
mainAxisSpacing: 5,
|
|
crossAxisSpacing: 10,
|
|
padding: EdgeInsets.all(4),
|
|
children: _tiles
|
|
)
|
|
)),
|
|
new Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: new List<Widget>()
|
|
{
|
|
new MaterialButton(height: 100, minWidth: 100, color: Colors.amber,
|
|
onPressed: () => { setState(() => { count++; }); }),
|
|
|
|
new MaterialButton(height: 100, minWidth: 100, color: Colors.amber,
|
|
onPressed: () => { setState(() => { count--; }); }),
|
|
|
|
new MaterialButton(height: 100, minWidth: 100, color: Colors.amber,
|
|
onPressed: () =>
|
|
{
|
|
setState(() =>
|
|
{
|
|
Debug.Log($"tile count {_tiles.Count}");
|
|
_tiles.RemoveAt(0);
|
|
Debug.Log($"tile count {_tiles.Count}");
|
|
_staggeredTiles.RemoveAt(0);
|
|
});
|
|
}),
|
|
|
|
new MaterialButton(height: 100, minWidth: 100, color: Colors.amber,
|
|
onPressed: () =>
|
|
{
|
|
setState(() =>
|
|
{
|
|
Debug.Log($"x tile count {_tiles.Count}");
|
|
_tiles.Add(
|
|
new _Example01Tile(
|
|
Utils.colors[Utils.random.Next(Utils.colors.Count)],
|
|
Icons.widgets,
|
|
Utils.lotties[Utils.random.Next(Utils.lotties.Count)]
|
|
)
|
|
);
|
|
Debug.Log($"y tile count {_tiles.Count}");
|
|
_staggeredTiles.Add(
|
|
StaggeredTile.count(
|
|
Utils.random.Next(2) + 1,
|
|
Utils.random.Next(2) + 1)
|
|
);
|
|
});
|
|
})
|
|
}
|
|
)
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
internal class _Example01Tile : StatefulWidget
|
|
{
|
|
internal _Example01Tile(Color backgroundColor, IconData iconData, string path)
|
|
{
|
|
this.backgroundColor = backgroundColor;
|
|
this.iconData = iconData;
|
|
this.path = path;
|
|
}
|
|
|
|
public readonly Color backgroundColor;
|
|
public readonly IconData iconData;
|
|
public readonly string path;
|
|
|
|
|
|
public override State createState()
|
|
{
|
|
return new _Example01TileState();
|
|
}
|
|
}
|
|
|
|
internal class _Example01TileState : State<_Example01Tile>
|
|
{
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
return new Card(
|
|
color: widget.backgroundColor,
|
|
child: new InkWell(
|
|
onTap: () =>
|
|
{
|
|
},
|
|
child: new Center(
|
|
child: new Padding(
|
|
padding: EdgeInsets.all(4),
|
|
child: new Lottie(widget.path, size: new Size(100, 100))
|
|
)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|