Search packages, repositories and app categories

GitHub repositorygtgalone/confirm_dialog

confirm_dialog

Confirm Dialog Widget for Flutter(JS-LIKE).

confirm_dialog project cover
Stars
6
Forks
0
Last push (UTC)
Oct 26, 2024
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

Confirm Dialog

pub package

Confirm Dialog Widget for Flutter(JS-LIKE). https://pub.dev/packages/confirm_dialog

Dialog colors follow app's theme.

screenshot

Installation

Add pubspec.yaml
dependencies:
  confirm_dialog: ^1.0.4

Usage

Basic
import 'package:confirm_dialog/confirm_dialog.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: TextButton(
          child: const Text('Confirm Dialog'),
          onPressed: () async {
            if (await confirm(context)) {
              return print('pressedOK');
            }
            return print('pressedCancel');
          },
        ),
      ),
    );
  }
}
Custom Message
import 'package:confirm_dialog/confirm_dialog.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: TextButton(
          child: const Text('Confirm Dialog'),
          onPressed: () async {
            if (await confirm(
              context,
              title: const Text('Confirm'),
              content: const Text('Would you like to remove?'),
              textOK: const Text('Yes'),
              textCancel: const Text('No'),
            )) {
              return print('pressedOK');
            }
            return print('pressedCancel');
          },
        ),
      ),
    );
  }
}

Recommend Libraries

Maintainer

License

MIT

Jehun Seem(심제훈) GitHub avatar
GitHub author

Jehun Seem(심제훈) ↗

Glory to God alone! Flutter, React(next.js), GraphQL, Docker, Serverless, Micro Service. Any questions : jehunseem@gmail.com.

dSPECTERSouth Korea
LanguagesDart

Packages published by this repository

Dependencies used

Dependency list 2 items

  • flutter{"sdk":"flutter"}
  • flutter_testDevelopment{"sdk":"flutter"}

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗