浏览代码

add StreamBuilderSample

/main
Xingwei Zhu 3 年前
当前提交
d3cc903c
共有 2 个文件被更改,包括 61 次插入0 次删除
  1. 58
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/StreamBuilderSample.cs
  2. 3
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/StreamBuilderSample.cs.meta

58
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/StreamBuilderSample.cs


using System;
using Unity.UIWidgets.async;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample
{
public class StreamBuilderSample : UIWidgetsPanel
{
protected override void main()
{
ui_.runApp(
new MyStreamBuilderWidget()
);
}
}
class MyStreamBuilderWidget : StatelessWidget
{
private Stream<int> counter()
{
return Stream<int>.periodic(new TimeSpan(0, 0, 0, 1), i =>
{
return i * 3;
}).take(5);
}
public override Widget build(BuildContext context)
{
return new WidgetsApp(
title: "Text Fields",
home: new StreamBuilder<int>(
stream: counter(),
builder: (BuildContext sub_context, AsyncSnapshot<int> snapshot) =>
{
if (snapshot.hasError)
return new Text($"Error: {snapshot.error}");
switch (snapshot.connectionState) {
case ConnectionState.none:
return new Text("没有Stream");
case ConnectionState.waiting:
return new Text("等待数据...");
case ConnectionState.active:
return new Text($"active: {snapshot.data}");
case ConnectionState.done:
return new Text("Stream已关闭");
}
return null; // unreachable
}
),
pageRouteBuilder: (settings, builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context)
)
);
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/StreamBuilderSample.cs.meta


fileFormatVersion: 2
guid: 97f298138594499f8355a91dab4721fc
timeCreated: 1629451124
正在加载...
取消
保存