diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3d260e6..8b0cf65 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100644 index 0000000..512c9c8 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=C:\flutter" +export "FLUTTER_APPLICATION_PATH=G:\Projets\packages\sweetalert\example" +export "FLUTTER_TARGET=lib\main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" diff --git a/example/lib/main.dart b/example/lib/main.dart index 1c3328c..e93639e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,8 @@ import 'dart:ui'; -import 'package:flutter_sequence_animation/flutter_sequence_animation.dart'; import 'package:sweetalert/sweetalert.dart'; import 'package:flutter/material.dart'; -import 'dart:math' as Math; import 'package:vector_math/vector_math_64.dart' as math; void main() => runApp(MyApp()); @@ -80,7 +78,10 @@ class _MyHomePageState extends State { new Text("Basic usage"), new RaisedButton( onPressed: () { - SweetAlert.show(context, title: "Just show a message"); + SweetAlert.show(context, + title: "Just show a message", + titlePadding: EdgeInsets.all(20.0), + titleAlign: TextAlign.center); }, child: new Text("Try me"), color: SweetAlert.success, @@ -89,9 +90,13 @@ class _MyHomePageState extends State { new Text("Title with subtitle"), new RaisedButton( onPressed: () { - SweetAlert.show(context, - title: "Just show a message", - subtitle: "Sweet alert is pretty"); + SweetAlert.show( + context, + title: "Just show a message", + titleAlign: TextAlign.center, + subtitle: "Sweet alert is pretty", + subtitlePadding: EdgeInsets.all(8.0), + ); }, child: new Text("Try me"), color: SweetAlert.success, @@ -100,10 +105,12 @@ class _MyHomePageState extends State { new Text("A success message"), new RaisedButton( onPressed: () { - SweetAlert.show(context, - title: "Just show a message", - subtitle: "Sweet alert is pretty", - style: SweetAlertStyle.success); + SweetAlert.show( + context, + title: "Just show a message", + subtitle: "Sweet alert is pretty", + style: SweetAlertStyle.success, + ); }, child: new Text("Try me"), color: SweetAlert.success, @@ -113,18 +120,23 @@ class _MyHomePageState extends State { "A warning message,with a function action on \"Confirm\"-button"), new RaisedButton( onPressed: () { - SweetAlert.show(context, - title: "Just show a message", - subtitle: "Sweet alert is pretty", - style: SweetAlertStyle.confirm, - showCancelButton: true, onPress: (bool isConfirm) { - if (isConfirm) { - SweetAlert.show(context,style: SweetAlertStyle.success,title: "Success"); + SweetAlert.show( + context, + title: "Just show a message", + subtitle: "Sweet alert is pretty", + style: SweetAlertStyle.confirm, + showCancelButton: true, + onPress: (bool isConfirm) { + if (isConfirm) { + SweetAlert.show(context, + style: SweetAlertStyle.success, title: "Success"); - // return false to keep dialog - return false; - } - }); + // return false to keep dialog + return false; + } else + return true; + }, + ); }, child: new Text("Try me"), color: SweetAlert.success, @@ -137,13 +149,21 @@ class _MyHomePageState extends State { subtitle: "Do you want to delete this message", style: SweetAlertStyle.confirm, showCancelButton: true, onPress: (bool isConfirm) { - if(isConfirm){ - SweetAlert.show(context,subtitle: "Deleting...", style: SweetAlertStyle.loading); - new Future.delayed(new Duration(seconds: 2),(){ - SweetAlert.show(context,subtitle: "Success!", style: SweetAlertStyle.success); + if (isConfirm) { + SweetAlert.show(context, + subtitle: "Deleting...", + style: SweetAlertStyle.loading); + new Future.delayed(new Duration(seconds: 2), () { + SweetAlert.show(context, + subtitle: "Success!", + style: SweetAlertStyle.success); }); - }else{ - SweetAlert.show(context,subtitle: "Canceled!", style: SweetAlertStyle.error); + } else { + SweetAlert.show( + context, + subtitle: "Canceled!", + style: SweetAlertStyle.error, + ); } // return false to keep dialog return false; @@ -153,8 +173,6 @@ class _MyHomePageState extends State { color: SweetAlert.success, textColor: Colors.white, ), - - new Text("Do a job that may fail"), new RaisedButton( onPressed: () { @@ -162,20 +180,30 @@ class _MyHomePageState extends State { subtitle: "Do you want to delete this message", style: SweetAlertStyle.confirm, showCancelButton: true, onPress: (bool isConfirm) { - if (isConfirm) { - //Return false to keep dialog - if(isConfirm){ - SweetAlert.show(context,subtitle: "Deleting...", style: SweetAlertStyle.loading); - new Future.delayed(new Duration(seconds: 2),(){ - SweetAlert.show(context,subtitle: "Job fail!", style: SweetAlertStyle.error); - }); - }else{ - SweetAlert.show(context,subtitle: "Canceled!", style: SweetAlertStyle.error); - } - return false; - } - - }); + if (isConfirm) { + //Return false to keep dialog + if (isConfirm) { + SweetAlert.show(context, + subtitle: "Deleting...", + style: SweetAlertStyle.loading); + new Future.delayed(new Duration(seconds: 2), () { + SweetAlert.show( + context, + subtitle: "Job fail!", + style: SweetAlertStyle.error, + ); + }); + } else { + SweetAlert.show( + context, + subtitle: "Canceled!", + style: SweetAlertStyle.error, + ); + } + return false; + } else + return true; + }); }, child: new Text("Try me"), color: SweetAlert.success, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 40ce07e..29f21d4 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" dependencies: flutter: diff --git a/lib/src/cancel.dart b/lib/src/cancel.dart index f246e22..1c9ebf0 100644 --- a/lib/src/cancel.dart +++ b/lib/src/cancel.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:sweetalert/sweetalert.dart'; -import 'dart:math' as Math; import 'package:vector_math/vector_math_64.dart' as math; import 'dart:ui'; import 'package:flutter_sequence_animation/flutter_sequence_animation.dart'; @@ -20,7 +19,7 @@ class CancelViewState extends State @override void initState() { - int factor = 50; + //int factor = 50; animationController = new AnimationController(vsync: this); sequenceAnimation = new SequenceAnimationBuilder() diff --git a/lib/src/confirm.dart b/lib/src/confirm.dart index 432eacf..ed3074b 100644 --- a/lib/src/confirm.dart +++ b/lib/src/confirm.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; -import 'dart:math' as Math; import 'package:vector_math/vector_math_64.dart' as math; import 'dart:ui'; -import 'package:flutter_sequence_animation/flutter_sequence_animation.dart'; class ConfirmView extends StatefulWidget { @override @@ -19,7 +17,7 @@ class ConfirmViewState extends State @override void initState() { - int factor = 50; + //int factor = 50; animationController = new AnimationController(vsync: this); animation = new ColorTween(begin: new Color(0xffF7D58B), end: new Color(0xffF2A665)) diff --git a/lib/src/success.dart b/lib/src/success.dart index 8d8db90..c394450 100644 --- a/lib/src/success.dart +++ b/lib/src/success.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'dart:math' as Math; import 'package:vector_math/vector_math_64.dart' as math; import 'dart:ui'; import 'package:flutter_sequence_animation/flutter_sequence_animation.dart'; diff --git a/lib/sweetalert.dart b/lib/sweetalert.dart index f5c86c1..f483140 100644 --- a/lib/sweetalert.dart +++ b/lib/sweetalert.dart @@ -1,22 +1,28 @@ library sweetalert; -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:sweetalert/src/cancel.dart'; import 'package:sweetalert/src/confirm.dart'; import 'package:sweetalert/src/success.dart'; - /// Return false to keey dialog showing typedef bool SweetAlertOnPress(bool isConfirm); enum SweetAlertStyle { success, error, confirm, loading } class SweetAlertOptions { + /// The title string final String title; + + /// The subtitle string final String subtitle; + /// The padding of the title text + final EdgeInsets titlePadding; + + /// The padding of the subtitle text + final EdgeInsets subtitlePadding; + final SweetAlertOnPress onPress; /// if null, @@ -37,19 +43,29 @@ class SweetAlertOptions { /// If set to true, two buttons will be displayed. final bool showCancelButton; - final SweetAlertStyle style; - SweetAlertOptions( - {this.showCancelButton: false, - this.title, - this.subtitle, - this.onPress, - this.cancelButtonColor, - this.cancelButtonText, - this.confirmButtonColor, - this.confirmButtonText, - this.style}); + /// The alignment of the title text + final TextAlign titleAlign; + + /// The alignment of the subtitle text + final TextAlign subtitleAlign; + + SweetAlertOptions({ + this.showCancelButton: false, + this.title, + this.subtitle, + this.onPress, + this.cancelButtonColor, + this.cancelButtonText, + this.confirmButtonColor, + this.confirmButtonText, + this.style, + this.titlePadding, + this.subtitlePadding, + this.titleAlign, + this.subtitleAlign, + }); } class SweetAlertDialog extends StatefulWidget { @@ -103,16 +119,12 @@ class SweetAlertDialogState extends State } void confirm() { - if (_options.onPress != null && _options.onPress(true) == false) - return; + if (_options.onPress != null && _options.onPress(true) == false) return; Navigator.pop(context); } - - void cancel() { - if (_options.onPress != null && _options.onPress(false) == false) - return; + if (_options.onPress != null && _options.onPress(false) == false) return; Navigator.pop(context); } @@ -154,18 +166,27 @@ class SweetAlertDialogState extends State } if (_options.title != null) { - listOfChildren.add(new Text( - _options.title, - style: new TextStyle(fontSize: 25.0, color: new Color(0xff575757)), + listOfChildren.add(Padding( + padding: this._options.titlePadding ?? EdgeInsets.only(left: 10.0, top: 10.0), + child: new Text( + _options.title, + textAlign: this._options.titleAlign ?? TextAlign.left, + style: new TextStyle( + fontSize: 25.0, + color: new Color(0xff575757), + ), + ), )); } if (_options.subtitle != null) { listOfChildren.add(new Padding( - padding: new EdgeInsets.only(top: 10.0), + padding: + this._options.subtitlePadding ?? new EdgeInsets.only(top: 10.0), child: new Text( _options.subtitle, style: new TextStyle(fontSize: 16.0, color: new Color(0xff797979)), + textAlign: this._options.subtitleAlign ?? TextAlign.left, ), )); } @@ -208,6 +229,7 @@ class SweetAlertDialogState extends State color: _options.confirmButtonColor ?? SweetAlert.success, child: new Text( _options.confirmButtonText ?? SweetAlert.successText, + textAlign: TextAlign.center, style: new TextStyle(color: Colors.white, fontSize: 16.0), ), ), @@ -224,15 +246,16 @@ class SweetAlertDialogState extends State child: new ClipRRect( borderRadius: new BorderRadius.all(new Radius.circular(5.0)), child: new Container( - color: Colors.white, - width: double.infinity, - child: new Padding( - padding: new EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 20.0), - child: new Column( - mainAxisSize: MainAxisSize.min, - children: listOfChildren, - ), - )), + color: Colors.white, + width: double.infinity, + child: new Padding( + padding: new EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 20.0), + child: new Column( + mainAxisSize: MainAxisSize.min, + children: listOfChildren, + ), + ), + ), ), ); })); @@ -258,18 +281,24 @@ abstract class SweetAlert { static SweetAlertDialogState _state; - static void show(BuildContext context, - {Curve curve, - String title, - String subtitle, - bool showCancelButton: false, - SweetAlertOnPress onPress, - Color cancelButtonColor, - Color confirmButtonColor, - String cancelButtonText, - String confirmButtonText, - SweetAlertStyle style}) { - SweetAlertOptions options = new SweetAlertOptions( + static void show( + BuildContext context, { + Curve curve, + String title, + String subtitle, + EdgeInsets titlePadding, + EdgeInsets subtitlePadding, + bool showCancelButton: false, + SweetAlertOnPress onPress, + Color cancelButtonColor, + Color confirmButtonColor, + String cancelButtonText, + String confirmButtonText, + TextAlign titleAlign, + TextAlign subtitleAlign, + SweetAlertStyle style, + }) { + SweetAlertOptions options = new SweetAlertOptions( showCancelButton: showCancelButton, title: title, subtitle: subtitle, @@ -278,28 +307,29 @@ abstract class SweetAlert { confirmButtonColor: confirmButtonColor, confirmButtonText: confirmButtonText, cancelButtonText: cancelButtonText, - cancelButtonColor: confirmButtonColor); - if(_state!=null){ + cancelButtonColor: cancelButtonColor, + titlePadding: titlePadding, + subtitlePadding: subtitlePadding, + titleAlign: titleAlign, + subtitleAlign: subtitleAlign); + if (_state != null) { _state.update(options); - }else{ + } else { showDialog( - context: context, - builder: (BuildContext context) { - return new Container( - color: Colors.transparent, - child: new Padding( - padding: new EdgeInsets.all(40.0), - child: new Scaffold( - backgroundColor: Colors.transparent, - body: new SweetAlertDialog( - curve: curve, - options:options - ), - ), + context: context, + builder: (BuildContext context) { + return new Container( + color: Colors.transparent, + child: new Padding( + padding: new EdgeInsets.all(40.0), + child: new Scaffold( + backgroundColor: Colors.transparent, + body: new SweetAlertDialog(curve: curve, options: options), ), - ); - }); + ), + ); + }, + ); } - } } diff --git a/pubspec.lock b/pubspec.lock index fce7ab7..83f7b7a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,34 +1,62 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.4.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.2" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -38,7 +66,7 @@ packages: dependency: "direct main" description: name: flutter_sequence_animation - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "3.0.1" flutter_test: @@ -46,34 +74,55 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.6" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.4" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: name: quiver - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -83,57 +132,64 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.9.3" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.11" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.6" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.4.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index f8f3aff..9b329ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: JZoom homepage: https://github.com/jzoom/sweetalert environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" dependencies: flutter: diff --git a/test/sweetalert_test.dart b/test/sweetalert_test.dart index 73f8a6a..efd7773 100644 --- a/test/sweetalert_test.dart +++ b/test/sweetalert_test.dart @@ -1,6 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sweetalert/sweetalert.dart'; void main() { test('adds one to input values', () {});