kalertflutter 2.0.0 copy "kalertflutter: ^2.0.0" to clipboard
kalertflutter: ^2.0.0 copied to clipboard

Flutter alert dialog library with success, error, warning, info, confirm, and prompt dialogs.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'KAlert Flutter Demo',
      debugShowCheckedModeBanner: false,
      themeMode: ThemeMode.system,
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: const Color(0xFF00D6C9),
        brightness: Brightness.light,
        scaffoldBackgroundColor: const Color(0xFFF4F7FB),
        appBarTheme: const AppBarTheme(
          centerTitle: false,
          backgroundColor: Color(0xFF0F172A),
          foregroundColor: Colors.white,
          elevation: 0,
        ),
      ),
      darkTheme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: const Color(0xFF00D6C9),
        brightness: Brightness.dark,
        scaffoldBackgroundColor: const Color(0xFF07111F),
        appBarTheme: const AppBarTheme(
          centerTitle: false,
          backgroundColor: Color(0xFF07111F),
          foregroundColor: Colors.white,
          elevation: 0,
        ),
      ),
      home: const HomePage(),
    );
  }
}

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

  static const String sampleImageUrl =
      'https://images.unsplash.com/photo-1659098602926-969fc12ef61a?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('KAlert Flutter Demo')),
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(18),
          children: [
            _buildHeader(context),

            const SizedBox(height: 22),

            _SectionTitle(
              title: 'Modern Styling',
              subtitle:
                  'Modern preset, custom appearance, font weight and professional dialog styling.',
            ),

            _DemoButton(
              title: 'Modern Success Dialog',
              icon: Icons.check_circle_rounded,
              color: const Color(0xFF10B981),
              onPressed: () {
                KAlertDialog.success(
                  context: context,
                  title: 'Success',
                  content:
                      'Your changes were saved successfully. This dialog uses the modern style preset.',
                  confirmText: 'Done',
                );
              },
            ),

            _DemoButton(
              title: 'Custom Radius, Elevation and Dim',
              icon: Icons.auto_awesome_rounded,
              color: const Color(0xFF2563EB),
              onPressed: () {
                KAlertDialog.show(
                  context: context,
                  title: 'Custom Appearance',
                  content:
                      'This dialog has custom corner radius, elevation and dim amount for a premium feel.',
                  type: KAlertType.normal,
                  style: KAlertStyle.modern,
                  cornerRadius: 30,
                  elevation: 20,
                  dimAmount: 0.60,
                  confirmText: 'Looks Good',
                );
              },
            ),

            _DemoButton(
              title: 'Title and Content Font Weight',
              icon: Icons.format_bold_rounded,
              color: const Color(0xFF7C3AED),
              onPressed: () {
                KAlertDialog.show(
                  context: context,
                  title: 'Font Weight Support',
                  content:
                      'You can control title, content and button font weights directly from the dialog API.',
                  type: KAlertType.normal,
                  style: KAlertStyle.modern,
                  titleFontWeight: FontWeight.w900,
                  contentFontWeight: FontWeight.w500,
                  confirmButtonFontWeight: FontWeight.w900,
                  confirmText: 'Awesome',
                );
              },
            ),

            const SizedBox(height: 24),

            _SectionTitle(
              title: 'Dialog Types',
              subtitle:
                  'Basic, success, error, warning, info and question dialogs.',
            ),

            _DemoButton(
              title: 'Basic Message Dialog',
              icon: Icons.chat_bubble_outline_rounded,
              color: const Color(0xFF334155),
              onPressed: () {
                KAlertDialog.show(
                  context: context,
                  title: 'Basic Message',
                  content:
                      'This is a clean basic message dialog. Existing simple APIs still work perfectly.',
                  type: KAlertType.normal,
                  style: KAlertStyle.classic,
                  confirmText: 'OK',
                );
              },
            ),

            _DemoButton(
              title: 'Error Dialog',
              icon: Icons.cancel_rounded,
              color: const Color(0xFFEF4444),
              onPressed: () {
                KAlertDialog.error(
                  context: context,
                  title: 'Something went wrong',
                  content:
                      'We could not complete this action. Please check your connection and try again.',
                  confirmText: 'Try Again',
                );
              },
            ),

            _DemoButton(
              title: 'Warning Confirm / Cancel Flow',
              icon: Icons.warning_rounded,
              color: const Color(0xFFF59E0B),
              onPressed: () async {
                final result = await KAlertDialog.warning(
                  context: context,
                  title: 'Delete this file?',
                  content:
                      'This action cannot be undone. You can confirm or cancel this action.',
                  confirmText: 'Delete',
                  cancelText: 'Cancel',
                );

                if (!context.mounted) return;

                if (result?.confirmed == true) {
                  KAlertDialog.success(
                    context: context,
                    title: 'Deleted',
                    content: 'The file has been deleted successfully.',
                    confirmText: 'OK',
                  );
                } else if (result?.cancelled == true) {
                  KAlertDialog.error(
                    context: context,
                    title: 'Cancelled',
                    content: 'Your file is safe. No changes were made.',
                    confirmText: 'OK',
                  );
                }
              },
            ),

            _DemoButton(
              title: 'Info Dialog',
              icon: Icons.info_rounded,
              color: const Color(0xFF0EA5E9),
              onPressed: () {
                KAlertDialog.info(
                  context: context,
                  title: 'Information',
                  content:
                      'This is an informational dialog for helpful updates or notices.',
                  confirmText: 'Got it',
                );
              },
            ),

            _DemoButton(
              title: 'Question Dialog',
              icon: Icons.help_rounded,
              color: const Color(0xFF8B5CF6),
              onPressed: () async {
                final result = await KAlertDialog.question(
                  context: context,
                  title: 'Continue?',
                  content: 'Do you want to continue with this action?',
                  confirmText: 'Yes',
                  cancelText: 'No',
                );

                if (!context.mounted) return;

                KAlertDialog.show(
                  context: context,
                  title: result?.confirmed == true ? 'Confirmed' : 'Cancelled',
                  content: result?.confirmed == true
                      ? 'You selected Yes.'
                      : 'You selected No.',
                  type: result?.confirmed == true
                      ? KAlertType.success
                      : KAlertType.warning,
                );
              },
            ),

            const SizedBox(height: 24),

            _SectionTitle(
              title: 'Input and Custom View',
              subtitle:
                  'Input validation, max length, keyboard type and custom Flutter widget support.',
            ),

            _DemoButton(
              title: 'Input Dialog with Validation',
              icon: Icons.edit_rounded,
              color: const Color(0xFF0EA5E9),
              onPressed: () async {
                final result = await KAlertDialog.input(
                  context: context,
                  title: 'Create Project',
                  content: 'Enter a project name with at least 3 characters.',
                  hintText: 'Project name',
                  initialValue: 'KAlertDialog',
                  maxLength: 30,
                  validator: (input) {
                    if (input.trim().length < 3) {
                      return 'Project name must be at least 3 characters';
                    }
                    return null;
                  },
                  onInputConfirm: (input) {
                    debugPrint('Created: $input');
                  },
                );

                if (!context.mounted) return;

                if (result?.confirmed == true) {
                  KAlertDialog.success(
                    context: context,
                    title: 'Created',
                    content: 'Project created: ${result?.value}',
                  );
                }
              },
            ),

            _DemoButton(
              title: 'Custom View Dialog',
              icon: Icons.dashboard_customize_rounded,
              color: const Color(0xFF14B8A6),
              onPressed: () {
                final controller = TextEditingController();

                KAlertDialog.customView(
                  context: context,
                  title: 'Custom View',
                  content: 'This dialog uses your own custom Flutter widget.',
                  showCancelButton: true,
                  confirmText: 'Save',
                  cancelText: 'Cancel',
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      TextField(
                        controller: controller,
                        decoration: const InputDecoration(
                          labelText: 'Project name',
                          hintText: 'Example: KAlertDialog Pro',
                          border: OutlineInputBorder(),
                        ),
                      ),
                      const SizedBox(height: 10),
                      const Text(
                        'You can place any custom widget inside KAlertDialog.',
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 12),
                      ),
                    ],
                  ),
                  onConfirm: () {
                    debugPrint('Saved: ${controller.text}');
                  },
                );
              },
            ),

            const SizedBox(height: 24),

            _SectionTitle(
              title: 'Images',
              subtitle:
                  'Custom image, URL circle image and big URL image examples.',
            ),

            _DemoButton(
              title: 'Custom Image Dialog',
              icon: Icons.image_rounded,
              color: const Color(0xFF6366F1),
              onPressed: () {
                KAlertDialog.customImage(
                  context: context,
                  title: 'Custom Image',
                  content:
                      'You can show an asset image, memory image or network image provider.',
                  image: const NetworkImage(sampleImageUrl),
                  confirmText: 'OK',
                );
              },
            ),

            _DemoButton(
              title: 'URL Image Circle',
              icon: Icons.account_circle_rounded,
              color: const Color(0xFF8B5CF6),
              onPressed: () {
                KAlertDialog.urlImage(
                  context: context,
                  title: 'Circle URL Image',
                  content: 'This example loads a remote image in circle mode.',
                  imageUrl: sampleImageUrl,
                  imageType: KAlertImageType.circle,
                  confirmText: 'Nice',
                );
              },
            ),

            _DemoButton(
              title: 'URL Image Big',
              icon: Icons.photo_size_select_actual_rounded,
              color: const Color(0xFFA855F7),
              onPressed: () {
                KAlertDialog.urlImage(
                  context: context,
                  title: 'Big URL Image',
                  content:
                      'This example loads a large image inside the dialog with fallback support.',
                  imageUrl: sampleImageUrl,
                  imageType: KAlertImageType.big,
                  confirmText: 'Close',
                );
              },
            ),

            const SizedBox(height: 24),

            _SectionTitle(
              title: 'Advanced Controls',
              subtitle:
                  'Buttons, callbacks, progress and backward compatible APIs.',
            ),

            _DemoButton(
              title: 'Button Styling',
              icon: Icons.smart_button_rounded,
              color: const Color(0xFF0891B2),
              onPressed: () {
                KAlertDialog.show(
                  context: context,
                  title: 'Button Styling',
                  content:
                      'This example shows button text size, font weight, all caps control and custom colors.',
                  type: KAlertType.normal,
                  style: KAlertStyle.minimal,
                  showCancelButton: true,
                  confirmText: 'Accept',
                  cancelText: 'Decline',
                  confirmButtonColor: const Color(0xFF10B981),
                  cancelButtonColor: const Color(0xFFE2E8F0),
                  cancelTextColor: const Color(0xFF334155),
                  confirmButtonFontWeight: FontWeight.w900,
                  cancelButtonFontWeight: FontWeight.w900,
                  buttonTextSize: 15,
                  confirmButtonAllCaps: false,
                  cancelButtonAllCaps: false,
                );
              },
            ),

            _DemoButton(
              title: 'Progress Dialog',
              icon: Icons.sync_rounded,
              color: const Color(0xFF059669),
              onPressed: () async {
                KAlertDialog.progress(
                  context: context,
                  title: 'Processing',
                  content: 'Please wait while we prepare your request.',
                  barrierDismissible: false,
                );

                await Future.delayed(const Duration(seconds: 3));

                if (!context.mounted) return;

                Navigator.of(context).pop();

                KAlertDialog.success(
                  context: context,
                  title: 'Completed',
                  content: 'Your request has been completed successfully.',
                  confirmText: 'Done',
                );
              },
            ),

            _DemoButton(
              title: 'Show and Dismiss Callbacks',
              icon: Icons.notifications_active_rounded,
              color: const Color(0xFF475569),
              onPressed: () {
                KAlertDialog.show(
                  context: context,
                  title: 'Callbacks',
                  content:
                      'This dialog shows onShow, onDismiss, onConfirm and onCancel examples.',
                  type: KAlertType.normal,
                  style: KAlertStyle.modern,
                  showCancelButton: true,
                  confirmText: 'Confirm',
                  cancelText: 'Cancel',
                  onShow: () {
                    debugPrint('Dialog shown');
                  },
                  onDismiss: () {
                    debugPrint('Dialog dismissed');
                  },
                  onConfirm: () {
                    debugPrint('Confirmed');
                  },
                  onCancel: () {
                    debugPrint('Cancelled');
                  },
                );
              },
            ),

            _DemoButton(
              title: 'Old API: KAlert.show()',
              icon: Icons.history_rounded,
              color: const Color(0xFF0F766E),
              onPressed: () {
                KAlert.show(
                  context,
                  title: 'Backward Compatible',
                  message:
                      'Your old KAlert.show() API still works with the new dialog UI.',
                  type: KAlertType.success,
                );
              },
            ),

            _DemoButton(
              title: 'Old API: KAlert.confirm()',
              icon: Icons.fact_check_rounded,
              color: const Color(0xFF9333EA),
              onPressed: () async {
                final result = await KAlert.confirm(
                  context,
                  title: 'Old Confirm API',
                  message:
                      'This uses the old KAlert.confirm() method but shows the new UI.',
                );

                if (!context.mounted) return;

                KAlert.show(
                  context,
                  title: result == true ? 'Confirmed' : 'Cancelled',
                  message: result == true
                      ? 'You confirmed the action.'
                      : 'You cancelled the action.',
                  type: result == true
                      ? KAlertType.success
                      : KAlertType.warning,
                );
              },
            ),

            _DemoButton(
              title: 'Old API: KAlert.prompt()',
              icon: Icons.keyboard_alt_rounded,
              color: const Color(0xFF2563EB),
              onPressed: () async {
                final value = await KAlert.prompt(
                  context,
                  title: 'Enter your name',
                  hintText: 'Your name',
                );

                if (!context.mounted) return;

                if (value != null && value.trim().isNotEmpty) {
                  KAlert.show(
                    context,
                    title: 'Hello',
                    message: value,
                    type: KAlertType.success,
                  );
                }
              },
            ),

            const SizedBox(height: 28),
          ],
        ),
      ),
    );
  }

  Widget _buildHeader(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(22),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(26),
        gradient: const LinearGradient(
          colors: [Color(0xFF0F172A), Color(0xFF111827)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.18),
            blurRadius: 24,
            offset: const Offset(0, 12),
          ),
        ],
      ),
      child: const Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'KAlert Flutter',
            style: TextStyle(
              color: Colors.white,
              fontSize: 30,
              fontWeight: FontWeight.w900,
              letterSpacing: -1,
            ),
          ),
          SizedBox(height: 8),
          Text(
            'Professional Flutter dialog demo matching the Android Java KAlertDialog library.',
            style: TextStyle(
              color: Color(0xFFCBD5E1),
              fontSize: 14,
              height: 1.5,
            ),
          ),
          SizedBox(height: 14),
          _VersionBadge(),
        ],
      ),
    );
  }
}

class _VersionBadge extends StatelessWidget {
  const _VersionBadge();

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(
        color: Color(0xFF1F2937),
        borderRadius: BorderRadius.all(Radius.circular(999)),
      ),
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 12, vertical: 7),
        child: Text(
          'Modern UI Demo',
          style: TextStyle(
            color: Color(0xFF86EFAC),
            fontSize: 12,
            fontWeight: FontWeight.w800,
          ),
        ),
      ),
    );
  }
}

class _SectionTitle extends StatelessWidget {
  final String title;
  final String subtitle;

  const _SectionTitle({required this.title, required this.subtitle});

  @override
  Widget build(BuildContext context) {
    final isDark = Theme.of(context).brightness == Brightness.dark;

    return Padding(
      padding: const EdgeInsets.only(bottom: 12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: TextStyle(
              color: isDark ? Colors.white : const Color(0xFF0F172A),
              fontSize: 20,
              fontWeight: FontWeight.w900,
              letterSpacing: -0.4,
            ),
          ),
          const SizedBox(height: 4),
          Text(
            subtitle,
            style: TextStyle(
              color: isDark ? const Color(0xFF94A3B8) : const Color(0xFF64748B),
              fontSize: 13,
              height: 1.45,
            ),
          ),
        ],
      ),
    );
  }
}

class _DemoButton extends StatelessWidget {
  final String title;
  final IconData icon;
  final Color color;
  final VoidCallback onPressed;

  const _DemoButton({
    required this.title,
    required this.icon,
    required this.color,
    required this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 11),
      child: SizedBox(
        width: double.infinity,
        height: 58,
        child: ElevatedButton(
          onPressed: onPressed,
          style: ElevatedButton.styleFrom(
            elevation: 0,
            backgroundColor: color,
            foregroundColor: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(18),
            ),
          ),
          child: Row(
            children: [
              Icon(icon, size: 22),
              const SizedBox(width: 12),
              Expanded(
                child: Text(
                  title,
                  style: const TextStyle(
                    fontSize: 15,
                    fontWeight: FontWeight.w800,
                  ),
                ),
              ),
              const Icon(Icons.arrow_forward_ios_rounded, size: 16),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
243
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter alert dialog library with success, error, warning, info, confirm, and prompt dialogs.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on kalertflutter