flutter_sweet_alert 0.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 77

flutter_sweet_alert

SweetAlert plugin for Flutter.

Supported Platforms

  • Android
  • IOS

How to Use

Android

1.add flutter_sweet_alert: ^0.0.2 to your pubspec.yaml

flutter_sweet_alert: ^0.0.2 添加到pubspec.yaml

2.add xmlns:tools="http://schemas.android.com/tools" to the manifest tag in AndroidManifest.xml .

xmlns:tools="http://schemas.android.com/tools" 添加到AndroidManifest.xml的manifest标签。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fmtol.xxx"
    xmlns:tools="http://schemas.android.com/tools">

3.add tools:replace="android:label,android:icon" to the application tag in AndroidManifest.xml.

tools:replace="android:label,android:icon" 添加到AndroidManifest.xml的application标签。

<application
        tools:replace="android:label,android:icon"
        ...
</application>

4.import 'package:flutter_sweet_alert/flutter_sweet_alert.dart' in your dart file.

在dart文件中import 'package:flutter_sweet_alert/flutter_sweet_alert.dart'

SweetAlert.dialog(
    type: AlertType.WARNING,
    title: "auto close",
    content: "auto close in 2 seconds",
    autoClose: 2000,
);

API Documentation API文档

  1. AlertType
Typedescription
AlertType.NORMALdialog without icon. 无图标弹窗
AlertType.ERRORdialog with a error icon. 带失败图标的弹窗
AlertType.SUCCESSdialog with a success icon. 带成功图标的弹窗
AlertType.WARNINGdialog with a warning icon. 带警告图标的弹窗
AlertType.CUSTOM_IMAGE_TYPEnot support. 暂不支持
AlertType.PROGRESSdialog with a progress icon. 带进度图标的弹窗
  1. SweetAlert.dialog()
PropertyTypeDefaultDescription
typeAlertTypeAlertType.NORMAL弹窗类型
titleStringnull弹窗标题
confirmButtonTextString确定确定按钮文字
showCancelboolfalse是否显示取消按钮
cancelButtonTextString取消取消按钮文字
cancelableStringnull点击弹窗外部关闭弹窗
autoCloseint0time of dialog auto close(ms).when 0,never auto close.自动关闭弹窗时间(毫秒),设为0时不自动关闭。
closeOnConfirmbooltrueClick on the confirm button to close the dialog, just support the dialog with results.点击确认按钮时是否关闭弹窗,仅适用于带结果的弹窗。
closeOnCancelbooltrueClick on the cancel button to close the dialog, just support the dialog with results.点击取消按钮时是否关闭弹窗,仅适用于带结果的弹窗。
  1. Response
ResponseDescription
trueclicked the confirm button. 点击确定按钮
falseclicked the cancel button. 点击取消按钮
autoclose return nothing. 自动关闭无返回值

0.0.1

  • Support Android Only.

0.0.2

  • Support iOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_sweet_alert/flutter_sweet_alert.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SweetAlert Plugin Demo'),
        ),
        body: Center(
          child: new Column(
            children: <Widget>[
              FlatButton(
                child: Text("Normal dialog 普通弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    content: "Content 弹窗内容",
                    confirmButtonText: "OK 确定",
                  );
                },
              ),
              FlatButton(
                child: Text("Normal dialog with title. 带标题的普通弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    title: "Title 标题",
                    content: "Content 弹窗内容",
                    confirmButtonText: "OK 确定",
                  );
                },
              ),
              FlatButton(
                child: Text("Success dialog 成功弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.SUCCESS,
                    title: "Title 标题",
                    content: "Content 弹窗内容",
                    confirmButtonText: "OK 确定",
                  );
                },
              ),
              FlatButton(
                child: Text("Warning dialog 警告弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.WARNING,
                    title: "Title 标题",
                    content: "Content 弹窗内容",
                    showCancel: true,
                    cancelButtonText: "Cancel 取消",
                    confirmButtonText: "Confirm 确定",
                  );
                },
              ),
              FlatButton(
                child: Text("Error dialog 失败弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.ERROR,
                    title: "Title 标题",
                    content: "Content 弹窗内容",
                    showCancel: false,
                    confirmButtonText: "Confirm 确定",
                  );
                },
              ),
              FlatButton(
                child: Text("auto close dialog 自动关闭弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.WARNING,
                    title: "Title 标题",
                    content: "auto close in 2 seconds. 2秒后自动关闭",
                    autoClose: 2000,
                    confirmButtonText: "Close 关闭",
                    cancelable: false,
                  );
                },
              ),
              FlatButton(
                child: Text("manual close dialog. 手动关闭弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.WARNING,
                    title: "Title 标题",
                    content: "manual close dialog in 1 second. 1秒后手动关闭弹窗",
                    confirmButtonText: "Close 关闭",
                    autoClose: 2000,
                    cancelable: false,
                  );
                  //delay 1 second then close the dialog. 延迟1秒后关闭
                  Future.delayed(Duration(seconds: 1)).then((_) {
                    SweetAlert.close();
                  });
                },
              ),
              FlatButton(
                child: Text("progress dialog 加载弹窗"),
                onPressed: () {
                  SweetAlert.loading(
                    cancelable: true,
                    title: "Title 标题",
                    content: "Content 内容",
                  );
                },
              ),
              FlatButton(
                child: Text("dialog with result 带结果的弹窗"),
                onPressed: () {
                  SweetAlert.dialog(
                    type: AlertType.WARNING,
                    cancelable: true,
                    title: "Title 标题",
                    content: "Content 内容",
                    showCancel: true,
                    cancelButtonText: "Cancel 取消",
                    confirmButtonText: "Confirm 确定",
                    closeOnConfirm: false,
                    closeOnCancel: false,
                  ).then((value) {
                    print(value);
                    if (value) {
                      SweetAlert.update(
                        type: AlertType.SUCCESS,
                        cancelable: true,
                        title: "done 完成",
                        content: "you pressed confirme 你点了确认",
                        showCancel: false,
                        closeOnConfirm: true,
                        confirmButtonText: "Confirm 确定",
                      ).then((value) {
                        print(value);
                      });
                    } else {
                      SweetAlert.update(
                        type: AlertType.SUCCESS,
                        cancelable: true,
                        title: "canceled 取消操作",
                        content: "you pressed cancele 你点了取消",
                        showCancel: false,
                        closeOnConfirm: true,
                        confirmButtonText: "Confirm 确定",
                      ).then((value) {
                        print(value);
                      });
                    }
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_sweet_alert: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_sweet_alert/flutter_sweet_alert.dart';
  
Version Uploaded Documentation Archive
0.1.0 Oct 24, 2018 Go to the documentation of flutter_sweet_alert 0.1.0 Download flutter_sweet_alert 0.1.0 archive
0.0.2 Oct 23, 2018 Go to the documentation of flutter_sweet_alert 0.0.2 Download flutter_sweet_alert 0.0.2 archive
0.0.1 Oct 20, 2018 Go to the documentation of flutter_sweet_alert 0.0.1 Download flutter_sweet_alert 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8