diff --git a/example/main.dart b/example/main.dart new file mode 100644 index 0000000..8cafb7e --- /dev/null +++ b/example/main.dart @@ -0,0 +1,56 @@ +import 'package:flutter/material.dart'; +import 'package:multiple_stream_builder/multiple_stream_builder.dart'; + +void main() { + runApp(const ExampleApp()); +} + +class ExampleApp extends StatelessWidget { + const ExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Multiple Stream Builder Example', + home: Scaffold( + appBar: AppBar( + title: const Text('Multiple Stream Builder Example'), + ), + body: const ExampleScreen(), + ), + ); + } +} + +class ExampleScreen extends StatefulWidget { + const ExampleScreen({Key? key}) : super(key: key); + + @override + State createState() => _ExampleScreenState(); +} + +class _ExampleScreenState extends State { + var stream1 = Stream.periodic(const Duration(seconds: 1), (x) => x); + var stream2 = Stream.periodic(const Duration(seconds: 2), (x) => x); + var stream3 = Stream.periodic(const Duration(seconds: 3), (x) => x); + + @override + Widget build(BuildContext context) { + return StreamBuilder3( + streams: StreamTuple3(stream1, stream2, stream3), + initialData: InitialDataTuple3(0, 0, 0), + builder: (context, snapshots) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('stream1: ${snapshots.snapshot1.data}'), + Text('stream2: ${snapshots.snapshot2.data}'), + Text('stream3: ${snapshots.snapshot3.data}'), + ], + ), + ); + }, + ); + } +}