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

A customizable alert dialog widget for Flutter with success, warning, info, and error types.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'V3C Alert Demo',
      theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
      home: const V3CAlertDemoPage(),
    );
  }
}

class V3CAlertDemoPage extends StatefulWidget {
  const V3CAlertDemoPage({super.key});

  @override
  State<V3CAlertDemoPage> createState() => _V3CAlertDemoPageState();
}

class _V3CAlertDemoPageState extends State<V3CAlertDemoPage> {
  String _lastAction = 'None';

  void _showSuccessAlert() {
    V3CAlert(
      context: context,
      title: 'Success!',
      description: 'Your operation has been completed successfully.',
      alertType: V3CAlertType.success,
      okOnPress: () {
        setState(() {
          _lastAction = 'Success alert - OK pressed';
        });
      },
      cancelOnPress: () {
        setState(() {
          _lastAction = 'Success alert - Cancelled';
        });
      },
    ).show();
  }

  void _showErrorAlert() {
    V3CAlert(
      context: context,
      title: 'Error!',
      description:
          'An error occurred while processing your request. Please try again.',
      alertType: V3CAlertType.error,
      okOnPress: () {
        setState(() {
          _lastAction = 'Error alert - OK pressed';
        });
      },
      cancelOnPress: () {
        setState(() {
          _lastAction = 'Error alert - Cancelled';
        });
      },
    ).show();
  }

  void _showWarningAlert() {
    V3CAlert(
      context: context,
      title: 'Warning!',
      description:
          'This action cannot be undone. Are you sure you want to continue?',
      alertType: V3CAlertType.warning,
      okOnPress: () {
        setState(() {
          _lastAction = 'Warning alert - Confirmed';
        });
      },
      cancelOnPress: () {
        setState(() {
          _lastAction = 'Warning alert - Cancelled';
        });
      },
    ).show();
  }

  void _showInfoAlert() {
    V3CAlert(
      context: context,
      title: 'Information',
      description:
          'This is an informational message to provide you with important details.',
      alertType: V3CAlertType.info,
      okOnPress: () {
        setState(() {
          _lastAction = 'Info alert - Acknowledged';
        });
      },
      cancelOnPress: () {
        setState(() {
          _lastAction = 'Info alert - Dismissed';
        });
      },
    ).show();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('V3C Alert Package Demo'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Text(
              'V3C Alert Demo',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 8),
            const Text(
              'Tap any button below to see different alert types in action:',
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 32),

            // Success Alert Button
            ElevatedButton.icon(
              onPressed: _showSuccessAlert,
              icon: const Icon(Icons.check_circle, color: Colors.green),
              label: const Text('Show Success Alert'),
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
            ),
            const SizedBox(height: 12),

            // Error Alert Button
            ElevatedButton.icon(
              onPressed: _showErrorAlert,
              icon: const Icon(Icons.bug_report, color: Colors.red),
              label: const Text('Show Error Alert'),
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
            ),
            const SizedBox(height: 12),

            // Warning Alert Button
            ElevatedButton.icon(
              onPressed: _showWarningAlert,
              icon: const Icon(Icons.warning, color: Colors.orange),
              label: const Text('Show Warning Alert'),
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
            ),
            const SizedBox(height: 12),

            const SizedBox(height: 12),
            // Info Alert Button
            ElevatedButton.icon(
              onPressed: _showInfoAlert,
              icon: const Icon(Icons.info, color: Colors.blue),
              label: const Text('Show Info Alert'),
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
            ),
            const SizedBox(height: 12),
            // Custom Text Alert Button
            ElevatedButton.icon(
              onPressed: () {
                V3CAlert(
                  context: context,
                  title: 'Custom Text',
                  description: 'This is an alert with custom button text.',
                  alertType: V3CAlertType.success,
                  okButtonText: 'Great!',
                  cancelButtonText: 'Disregard',
                  okOnPress: () {
                    setState(() {
                      _lastAction = 'Custom alert - Great pressed';
                    });
                  },
                  cancelOnPress: () {
                    setState(() {
                      _lastAction = 'Custom alert - Disregard pressed';
                    });
                  },
                ).show();
              },
              icon: const Icon(Icons.text_fields, color: Colors.purple),
              label: const Text('Show Custom Text Alert'),
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
            ),

            const SizedBox(height: 32),

            // Status Display
            Container(
              padding: const EdgeInsets.all(16),
              decoration: BoxDecoration(
                color: Colors.grey[100],
                borderRadius: BorderRadius.circular(8),
                border: Border.all(color: Colors.grey[300]!),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Text(
                    'Last Action:',
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
                  ),
                  const SizedBox(height: 4),
                  Text(_lastAction, style: const TextStyle(fontSize: 14)),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
160
points
135
downloads
screenshot

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A customizable alert dialog widget for Flutter with success, warning, info, and error types.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

flutter

More

Packages that depend on v3c_alert