i_toast 0.0.4 copy "i_toast: ^0.0.4" to clipboard
i_toast: ^0.0.4 copied to clipboard

Provides easy-to-use and non-intrusive toast messages with options for customization including duration, position, and appearance.

example/lib/main.dart

import 'package:example/widget_extensions.dart';
import 'package:flutter/material.dart';
import 'package:i_toast/i_toast.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'iToast Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const IToast(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final Map<ToastType, Color> toastTypes = {
      ToastType.error: ColorConstants.statesError.shade300,
      ToastType.info: ColorConstants.statesInfo.shade300,
      ToastType.success: ColorConstants.statesSuccess.shade300,
      ToastType.warning: ColorConstants.statesWarning.shade300
    };

    return Scaffold(
      appBar: AppBar(
        title: const Text("iToast Example"),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ...toastTypes.entries.map(
                (toast) {
                  return ElevatedButton(
                    onPressed: () {
                      _showToastMessage(
                        context,
                        toast.key.name.substring(0, 1).toUpperCase() +
                            toast.key.name.substring(1),
                        "${toast.key.name} description.",
                        toast.key,
                        leading: Icon(
                          Icons.info,
                          color: toast.value,
                        ),
                        trailing: Icon(
                          Icons.close,
                          color: toast.value,
                        ),
                      );
                    },
                    child: Text(
                        '${toast.key.name.toUpperCase()} with leading and trailing'),
                  ).addSize;
                },
              ),
              ...toastTypes.entries.map(
                (toast) {
                  return ElevatedButton(
                    onPressed: () {
                      _showToastMessage(
                        context,
                        toast.key.name.substring(0, 1).toUpperCase() +
                            toast.key.name.substring(1),
                        "${toast.key.name} description.",
                        toast.key,
                        trailing: Icon(
                          Icons.close,
                          color: toast.value,
                        ),
                      );
                    },
                    child: Text(
                        '${toast.key.name.toUpperCase()} without trailing'),
                  ).addSize;
                },
              ),
              ...toastTypes.entries.map(
                (toast) {
                  return ElevatedButton(
                    onPressed: () {
                      _showToastMessage(
                        context,
                        toast.key.name.substring(0, 1).toUpperCase() +
                            toast.key.name.substring(1),
                        "${toast.key.name} description.",
                        toast.key,
                        leading: Icon(
                          Icons.info,
                          color: toast.value,
                        ),
                      );
                    },
                    child:
                        Text('${toast.key.name.toUpperCase()} without leading'),
                  ).addSize;
                },
              ),
              ElevatedButton(
                onPressed: () {
                  _showToastMessage(
                    context,
                    'Custom iToast',
                    "Custom iToast description.",
                    ToastType.custom,
                    backgroundColor: Colors.blueGrey.shade50,
                    border: Border.all(
                      color: Colors.blueGrey,
                    ),
                    leading: const Icon(Icons.explore, color: Colors.teal),
                    borderRadius: BorderRadius.circular(24),
                    textColor: Colors.black,
                  );
                },
                child: const Text('Show Custom iToast'),
              ).addSize,
            ],
          ),
        ),
      ),
    );
  }
}

void _showToastMessage(
  BuildContext context,
  String title,
  String description,
  ToastType toastType, {
  Color? backgroundColor,
  Border? border,
  Widget? trailing,
  Widget? leading,
  Color? textColor,
  BorderRadius? borderRadius,
}) {
  IToastService.show(
    context,
    title: title,
    description: description,
    trailing: trailing,
    toastType: toastType,
    leading: leading,
    duration: Durations.extralong4,
    toastBackgroundColor: backgroundColor,
    toastBorder: border,
    toastBorderRadius: borderRadius,
    toastTextColor: textColor,
  );
}
7
likes
160
pub points
60%
popularity

Publisher

unverified uploader

Provides easy-to-use and non-intrusive toast messages with options for customization including duration, position, and appearance.

Repository (GitHub)
View/report issues

Topics

#animation #toast #message

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on i_toast