fdevs_pops 0.0.1+1-alpha copy "fdevs_pops: ^0.0.1+1-alpha" to clipboard
fdevs_pops: ^0.0.1+1-alpha copied to clipboard

A powerful and flexible Flutter package for managing overlays such as dialogs, snackbars, and custom overlays with unique identifiers.

example/lib/main.dart

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

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

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

  @override
  State<ShowcaseApp> createState() => _ShowcaseAppState();
}

class _ShowcaseAppState extends State<ShowcaseApp> {
  final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();

  @override
  Widget build(BuildContext context) {
    return FPops.init(
      rootNavigatorKey: _navigatorKey,
      child: MaterialApp(
        navigatorKey: _navigatorKey,
        home: HomePage(navigatorKey: _navigatorKey),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  final GlobalKey<NavigatorState> navigatorKey;

  const HomePage({super.key, required this.navigatorKey});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Multiple Dialogs Showcase')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            _showTextDialog(context);
            _showNumberDialog(context);
            _showChoiceDialog(context);
          },
          child: Text('Show Multiple Dialogs'),
        ),
      ),
    );
  }

  void _showSnackBar(String? result) {
    FPops.I.showSnackBar(
      id: 'snackbar_${DateTime.now().millisecondsSinceEpoch}',
      builder: (_) => Container(
        padding: EdgeInsets.all(16),
        color: Colors.blue,
        child: Text('Dialog dismissed with: ${result ?? 'Cancelled'}'),
      ),
      autoHideDuration: Duration(seconds: 3),
    );
  }

  void _showTextDialog(BuildContext context) async {
    final controller = TextEditingController();
    final result = await FPops.I.showDialog<String>(
      id: 'text_input',
      builder: (_) => AlertDialog(
        title: Text('Text Input Dialog'),
        content: TextField(
          controller: controller,
          decoration: InputDecoration(labelText: 'Enter your name'),
        ),
        actions: [
          TextButton(
            onPressed: () => FPops.I.dismiss('text_input', null),
            child: Text('Cancel'),
          ),
          ElevatedButton(
            onPressed: () => FPops.I.dismiss('text_input', controller.text),
            child: Text('Submit'),
          ),
        ],
      ),
    );
    _showSnackBar(result);
  }

  void _showNumberDialog(BuildContext context) async {
    final controller = TextEditingController();
    final result = await FPops.I.showDialog<String>(
      id: 'number_input',
      builder: (_) => AlertDialog(
        title: Text('Number Input Dialog'),
        content: TextField(
          controller: controller,
          decoration: InputDecoration(labelText: 'Enter your age'),
          keyboardType: TextInputType.number,
        ),
        actions: [
          TextButton(
            onPressed: () => FPops.I.dismiss('number_input', null),
            child: Text('Cancel'),
          ),
          ElevatedButton(
            onPressed: () => FPops.I.dismiss('number_input', controller.text),
            child: Text('Submit'),
          ),
        ],
      ),
    );
    _showSnackBar(result);
  }

  void _showChoiceDialog(BuildContext context) async {
    String? selectedGender;
    final result = await FPops.I.showDialog<String>(
      id: 'choice',
      builder: (_) => AlertDialog(
        title: Text('Choice Dialog'),
        content: StatefulBuilder(
          builder: (context, setState) => RadioGroup<String>(
            groupValue: selectedGender,
            onChanged: (value) => setState(() => selectedGender = value),
            child: Column(
              children: [
                ListTile(
                  title: Text('Male'),
                  leading: Radio<String>(value: 'Male'),
                  onTap: () => setState(() => selectedGender = 'Male'),
                ),
                ListTile(
                  title: Text('Female'),
                  leading: Radio<String>(value: 'Female'),
                  onTap: () => setState(() => selectedGender = 'Female'),
                ),
                ListTile(
                  title: Text('Other'),
                  leading: Radio<String>(value: 'Other'),
                  onTap: () => setState(() => selectedGender = 'Other'),
                ),
              ],
            ),
          ),
        ),
        actions: [
          TextButton(
            onPressed: () => FPops.I.dismiss('choice', null),
            child: Text('Cancel'),
          ),
          ElevatedButton(
            onPressed: () => FPops.I.dismiss('choice', selectedGender),
            child: Text('Submit'),
          ),
        ],
      ),
    );
    _showSnackBar(result);
  }
}
0
likes
150
points
3
downloads

Documentation

API reference

Publisher

verified publisherfdevs.org

Weekly Downloads

A powerful and flexible Flutter package for managing overlays such as dialogs, snackbars, and custom overlays with unique identifiers.

License

MIT (license)

Dependencies

flutter

More

Packages that depend on fdevs_pops