tfk_toast 0.2.4 copy "tfk_toast: ^0.2.4" to clipboard
tfk_toast: ^0.2.4 copied to clipboard

tfk_toast is a lightweight Flutter package for displaying customizable toast messages.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:tfk_toast/enum.dart';
import 'package:tfk_toast/tfk_toast.dart';

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

/// ======================================================
/// APP ROOT
/// Uses ONLY global navigatorKey (no context passed)
/// ======================================================
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: TfkToast.navigatorKey,
      home: const GlobalToastPage(),
    );
  }
}

/// ======================================================
/// PAGE 1
/// GLOBAL CONTEXT TOAST (NO BuildContext USED)
/// ======================================================
class GlobalToastPage extends StatelessWidget {
  const GlobalToastPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Global Toast Page"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text("GLOBAL CONTEXT TOASTS"),
            ElevatedButton(
              onPressed: () {
                TfkToast.showToast(
                  "This toast uses global navigatorKey only",
                  title: "Global Toast",
                  position: ToastPosition.top,
                  type: ToastType.info,
                );
              },
              child: const Text("Top Toast (Global)"),
            ),
            ElevatedButton(
              onPressed: () {
                TfkToast.showToast(
                  "Bottom global toast",
                  title: "Global",
                  position: ToastPosition.bottom,
                  type: ToastType.success,
                );
              },
              child: const Text("Bottom Toast (Global)"),
            ),
            ElevatedButton(
              onPressed: () {
                TfkToast.showToast(
                  "Center global toast",
                  title: "Global",
                  position: ToastPosition.center,
                  type: ToastType.warning,
                );
              },
              child: const Text("Center Toast (Global)"),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (_) => const LocalToastPage(),
                  ),
                );
              },
              child: const Text("Go to Local Context Page"),
            ),
          ],
        ),
      ),
    );
  }
}

/// ======================================================
/// PAGE 2
/// LOCAL CONTEXT TOAST (USES BuildContext)
/// ======================================================
class LocalToastPage extends StatelessWidget {
  const LocalToastPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Local Toast Page"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text("LOCAL CONTEXT TOASTS"),
            Builder(
              builder: (ctx) {
                return Column(
                  children: [
                    ElevatedButton(
                      onPressed: () {
                        TfkToast.showToast(
                          "Toast using BuildContext",
                          context: ctx,
                          title: "Local Toast",
                          type: ToastType.info,
                          position: ToastPosition.top,
                        );
                      },
                      child: const Text("Top Toast (Context)"),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        TfkToast.showToast(
                          "Bottom context toast",
                          context: ctx,
                          title: "Local",
                          type: ToastType.success,
                          position: ToastPosition.bottom,
                        );
                      },
                      child: const Text("Bottom Toast (Context)"),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        TfkToast.showToast(
                          "Center context toast",
                          context: ctx,
                          title: "Local",
                          type: ToastType.warning,
                          position: ToastPosition.center,
                        );
                      },
                      child: const Text("Center Toast (Context)"),
                    ),
                  ],
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
140
points
264
downloads

Documentation

API reference

Publisher

verified publisherdike.co.tz

Weekly Downloads

tfk_toast is a lightweight Flutter package for displaying customizable toast messages.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tfk_toast

Packages that implement tfk_toast