suspense 1.1.0+1 copy "suspense: ^1.1.0+1" to clipboard
suspense: ^1.1.0+1 copied to clipboard

A React-inspired Suspense implementation for your Flutter apps.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:suspense/suspense.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Suspense Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Suspense Flutter Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final rng = Random();
  Stream<int> _stream;

  @override
  void initState() {
    super.initState();

    _stream = Stream<int>.periodic(
      Duration(seconds: 1),
      (_) => rng.nextInt(10000),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Suspense<int>.stream(
          stream: _stream,
          fallback: CircularProgressIndicator(),
          builder: (data) => Text('Result: $data'),
          errorBuilder: (error) => Text('Uh oh! it didn\'t work: $error'),
        ),
      ),
    );
  }
}
2
likes
40
pub points
0%
popularity

Publisher

verified publishertusharsadhwani.dev

A React-inspired Suspense implementation for your Flutter apps.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on suspense