/
main.dart
50 lines (43 loc) · 1.37 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:example/delayed_text.dart';
import 'package:stream_summary_builder/stream_summary_builder.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Stream<String> _cachedTextStream = delayedText();
void _initStream() {
_cachedTextStream = delayedText();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Stream Summary Builder Demo',
home: SafeArea(
child: Scaffold(
body: StreamSummaryBuilder<String, String>(
initialData: '',
fold: (summary, value) => summary + value,
/// Simulates receiving text line by line from an asynchronous source
stream: _cachedTextStream,
builder: _displayTextSummary),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.refresh),
onPressed: () => setState(_initStream),
),
),
),
);
}
Widget _displayTextSummary(
BuildContext context, AsyncSnapshot<String> snapshot) {
return Align(
child: Text(snapshot.data ?? ''), alignment: Alignment.topLeft);
}
}