toaster_next 1.0.1 copy "toaster_next: ^1.0.1" to clipboard
toaster_next: ^1.0.1 copied to clipboard

Yet another Flutter Toaster. Built with ease of use and testablility in mind, with sensible defaults.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:toaster_next/toaster.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'toaster Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Toaster.mount(child: const Scaffold(body: AddToasts())),
    );
  }
}

class AddToasts extends StatefulWidget {
  const AddToasts({Key? key}) : super(key: key);

  @override
  State<AddToasts> createState() => _AddToastsState();
}

class _AddToastsState extends State<AddToasts> {
  int counter = 0;

  @override
  Widget build(BuildContext context) {
    return Center(
        child: ElevatedButton(
      child: const Text('Add Toast'),
      onPressed: () {
        setState(() {
          counter++;
        });
        Toaster.of(context).add(Toast(
            action: ToastAction(
                action: () => print('clicked on action'),
                actionText: 'Click me'),
            expireAt: null,
            onDismiss: () =>
                print('Ive been dismissed; the action was not performed'),
            message: counter.toString(),
            type: counter % 3 == 0
                ? warningToast
                : counter % 3 == 1
                    ? successToast
                    : errorToast));
      },
    ));
  }
}
1
likes
150
points
8
downloads

Publisher

unverified uploader

Weekly Downloads

Yet another Flutter Toaster. Built with ease of use and testablility in mind, with sensible defaults.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

clock, flutter

More

Packages that depend on toaster_next