more_widgets 4.1.0 copy "more_widgets: ^4.1.0" to clipboard
more_widgets: ^4.1.0 copied to clipboard

This package will offer you new useful widgets to use in your apps.

example/lib/main.dart

// A single-page demo app that showcases widgets from the local `more_widgets` package.
import 'package:flutter/material.dart';
import 'package:more_widgets/more_widgets.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'more_widgets - Example',
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo)),
      home: const ExampleHomePage(),
    );
  }
}

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

  @override
  State<ExampleHomePage> createState() => _ExampleHomePageState();
}

class _ExampleHomePageState extends State<ExampleHomePage> {
  late final TextEditingController _inputController;

  @override
  void initState() {
    super.initState();
    _inputController = TextEditingController();
  }

  @override
  void dispose() {
    _inputController.dispose();
    super.dispose();
  }

  void _showSnack(BuildContext context, String message) {
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
  }

  @override
  Widget build(BuildContext context) {
    return GradientBackground(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(title: const Text('more_widgets - Example')),
        body: SingleChildScrollView(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              const SizedBox(height: 8),

              // GradientButton demo
              const Text('GradientButton', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              GradientButton(
                buttonText: 'Press me',
                onPressed: () => _showSnack(context, 'GradientButton pressed'),
              ),

              const SizedBox(height: 24),

              // RoundedContainer demo
              const Text('RoundedContainer', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              RoundedContainer(
                color: Colors.white70,
                child: Padding(
                  padding: const EdgeInsets.all(12),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Text('This is a rounded container.'),
                      const SizedBox(height: 8),
                      TextButton(
                        onPressed: () => _showSnack(context, 'Inner button in RoundedContainer pressed'),
                        child: const Text('Inner action'),
                      )
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 24),

              // LoadingWidget demo
              const Text('LoadingWidget', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              Container(
                padding: const EdgeInsets.all(12),
                color: Colors.white70,
                child: const LoadingWidget(),
              ),

              const SizedBox(height: 24),

              // BottomActionSheet demo
              const Text('BottomActionSheet', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              ElevatedButton(
                onPressed: () {
                  BottomActionSheet.show(
                    context: context,
                    actions: [
                      BottomActionSheetAction(title: 'Action 1', onPressed: () => _showSnack(context, 'Action 1')),
                      BottomActionSheetAction(
                        title: 'Delete',
                        onPressed: () => _showSnack(context, 'Delete'),
                        isDestructiveAction: true,
                      ),
                    ],
                    title: 'Choose an action',
                    message: 'Select one of the available actions',
                    cancelButton: BottomActionSheetAction(title: 'Cancel', onPressed: () => _showSnack(context, 'Cancel')),
                  );
                },
                child: const Text('Show BottomActionSheet'),
              ),

              const SizedBox(height: 24),

              // Dialogs demo
              const Text('Dialogs', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              Wrap(
                spacing: 8,
                runSpacing: 8,
                children: [
                  ElevatedButton(
                    onPressed: () {
                      Dialogs.infoDialog(
                        context: context,
                        title: 'Info',
                        message:
                        'This is an informational dialog. This is an informational dialog. This is an informational dialog. '
                            'This is an informational dialog. This is an informational dialog. This is an informational dialog. ',
                        onPressed: () => _showSnack(context, 'Info OK'),
                      );
                    },
                    child: const Text('InfoDialog'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      Dialogs.dialogWithOptions(
                        context: context,
                        title: 'Confirm',
                        message: 'Do you want to continue?',
                        onPressedLeftButton: () => _showSnack(context, 'Left pressed'),
                        onPressedRightButton: () => _showSnack(context, 'Right pressed'),
                      );
                    },
                    child: const Text('DialogWithOptions'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      _inputController.clear();
                      Dialogs.textInputDialog(
                        context: context,
                        title: 'Input',
                        message: 'Enter some text',
                        controller: _inputController,
                        onChanged: (value) => _showSnack(context, 'Changed: $value'),
                        onPressedLeftButton: () => _showSnack(context, 'Left in Input'),
                        onPressedRightButton: () => _showSnack(context, 'Right in Input'),
                      );
                    },
                    child: const Text('TextInputDialog'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      Dialogs.loadingDialog(context: context, title: 'Loading');
                      final navigator = Navigator.of(context);
                      Future.delayed(const Duration(seconds: 2), () => navigator.pop());
                    },
                    child: const Text('LoadingDialog'),
                  ),
                ],
              ),

              const SizedBox(height: 24),

              // CheckBoxDialog demo (NEW)
              const Text('CheckBoxDialog', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 8),
              Wrap(
                spacing: 8,
                runSpacing: 8,
                children: [
                  ElevatedButton(
                    onPressed: () async {
                      final value = await Dialogs.checkBoxDialog(
                        context: context,
                        title: 'Preferences',
                        message: 'Would you like to remember this choice?',
                        checkboxLabel: 'Remember my choice',
                        initialValue: true,
                        textLeftButton: 'Not now',
                        textRightButton: 'Continue',
                        onPressedLeftButton: (checked) => _showSnack(context, 'Left pressed (checked=$checked)'),
                        onPressedRightButton: (checked) => _showSnack(context, 'Right pressed (checked=$checked)'),
                        defaultAction: DefaultAction.right,
                      );

                      _showSnack(context, 'Dialog closed (returned=$value)');
                    },
                    child: const Text('CheckBoxDialog (2 buttons)'),
                  ),
                  ElevatedButton(
                    onPressed: () async {
                      final value = await Dialogs.checkBoxDialog(
                        context: context,
                        title: 'Tip',
                        message: 'You can disable this message in settings.',
                        checkboxLabel: "Don't show again",
                        hasSecondaryButton: false,
                        textRightButton: 'Got it',
                        onPressedRightButton: (checked) => _showSnack(context, 'Got it (checked=$checked)'),
                      );

                      _showSnack(context, 'Dialog closed (returned=$value)');
                    },
                    child: const Text('CheckBoxDialog (1 button)'),
                  ),
                  ElevatedButton(
                    onPressed: () async {
                      final value = await Dialogs.checkBoxDialog(
                        context: context,
                        title: 'Danger zone',
                        message: 'This action cannot be undone.',
                        checkboxLabel: "Don't ask me again",
                        textLeftButton: 'Cancel',
                        textRightButton: 'Delete',
                        destructiveAction: DestructiveAction.right,
                        onPressedRightButton: (checked) =>
                            _showSnack(context, 'Delete pressed (checked=$checked)'),
                      );

                      _showSnack(context, 'Dialog closed (returned=$value)');
                    },
                    child: const Text('CheckBoxDialog (destructive)'),
                  ),
                ],
              ),

              const SizedBox(height: 40),
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
150
points
197
downloads

Publisher

unverified uploader

Weekly Downloads

This package will offer you new useful widgets to use in your apps.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on more_widgets