toastly 0.1.0 copy "toastly: ^0.1.0" to clipboard
toastly: ^0.1.0 copied to clipboard

A lightweight toast utility for Flutter apps with customizable icon, message, and animation.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Toastly Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();

    Toastly.init(
      vsync: this,
      stackMode: ToastlyStackMode.queue,
    );
  }

  void _show(ToastlyConfig config) {
    Toastly.instance.show(
      context: context,
      config: config,
    );
  }

  Widget _button(String label, VoidCallback onPressed) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6),
      child: ElevatedButton(onPressed: onPressed, child: Text(label)),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Toastly Example')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: ListView(
          children: [
            _button('Fade Animation (default)', () {
              _show(ToastlyConfig(
                message: const Text('This is a fade toast'),
                animationType: ToastAnimationType.fade,
              ));
            }),
            _button('Slide Up Animation', () {
              _show(ToastlyConfig(
                message: const Text('Sliding up!'),
                animationType: ToastAnimationType.slideUp,
              ));
            }),
            _button('Slide Down Animation', () {
              _show(ToastlyConfig(
                message: const Text('Sliding down!'),
                alignment: Alignment.topCenter,
                animationType: ToastAnimationType.slideDown,
              ));
            }),
            _button('Scale Animation (default)', () {
              _show(ToastlyConfig(
                message: const Text('Pop in!'),
                animationType: ToastAnimationType.scaleIn,
              ));
            }),
            _button('With Icon and Progress Bar', () {
              _show(ToastlyConfig(
                message: const Text('Saving...'),
                icon: const Icon(Icons.download),
                shouldShowProgressBar: true,
                progressBarColor: Colors.blueAccent,
                animationType: ToastAnimationType.slideUp,
                dismissInSeconds: 4,
              ));
            }),
            _button('Persistent with Close Button', () {
              _show(ToastlyConfig(
                message: const Text('This won’t auto-dismiss'),
                autoDismiss: false,
                closeItem: IconButton(
                  icon: const Icon(Icons.close),
                  onPressed: () => Toastly.instance.hide(),
                ),
                backgroundColor: Colors.orange[50],
                animationType: ToastAnimationType.scaleIn,
              ));
            }),
            _button('Fully Styled Toast', () {
              _show(ToastlyConfig(
                icon: const Icon(Icons.info_outline, color: Colors.deepPurple),
                message: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: const [
                    Text('Styled Toast',
                        style: TextStyle(fontWeight: FontWeight.bold)),
                    Text('Multiline, icon, bar, and animation.'),
                  ],
                ),
                backgroundColor: Colors.deepPurple.shade50,
                borderRadius: BorderRadius.circular(16),
                padding:
                    const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
                shouldShowProgressBar: true,
                progressBarColor: Colors.deepPurple,
                dismissInSeconds: 5,
                animationType: ToastAnimationType.slideUp,
                alignment: Alignment.bottomCenter,
              ));
            }),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight toast utility for Flutter apps with customizable icon, message, and animation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on toastly