Skip to content

Commit

Permalink
feat: add new widgets and mandatory update
Browse files Browse the repository at this point in the history
  • Loading branch information
kauemurakami committed Sep 24, 2022
1 parent c23d391 commit 9a97701
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus-1.4.3+1\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_ios-6.0.17\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus-1.4.3+1\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_android-6.0.19\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_macos-1.3.0\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-3.0.1\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_linux-1.0.5\\\\","native_build":false,"dependencies":[]},{"name":"url_launcher_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_linux-3.0.1\\\\","native_build":true,"dependencies":[]}],"windows":[{"name":"package_info_plus_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_windows-2.1.0\\\\","native_build":false,"dependencies":[]},{"name":"url_launcher_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_windows-3.0.1\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"package_info_plus_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_web-1.0.5\\\\","dependencies":[]},{"name":"url_launcher_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-2.0.13\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":["package_info_plus_linux","package_info_plus_macos","package_info_plus_windows","package_info_plus_web"]},{"name":"package_info_plus_linux","dependencies":[]},{"name":"package_info_plus_macos","dependencies":[]},{"name":"package_info_plus_web","dependencies":[]},{"name":"package_info_plus_windows","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-09-19 12:49:52.730828","version":"3.3.2"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus-1.4.3+1\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_ios-6.0.17\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus-1.4.3+1\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_android-6.0.19\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_macos-1.3.0\\\\","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-3.0.1\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_linux-1.0.5\\\\","native_build":false,"dependencies":[]},{"name":"url_launcher_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_linux-3.0.1\\\\","native_build":true,"dependencies":[]}],"windows":[{"name":"package_info_plus_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_windows-2.1.0\\\\","native_build":false,"dependencies":[]},{"name":"url_launcher_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_windows-3.0.1\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"package_info_plus_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info_plus_web-1.0.5\\\\","dependencies":[]},{"name":"url_launcher_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-2.0.13\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":["package_info_plus_linux","package_info_plus_macos","package_info_plus_windows","package_info_plus_web"]},{"name":"package_info_plus_linux","dependencies":[]},{"name":"package_info_plus_macos","dependencies":[]},{"name":"package_info_plus_web","dependencies":[]},{"name":"package_info_plus_windows","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-09-24 15:21:10.892301","version":"3.3.2"}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@

## 1.0.3
* Fixing loop index of Albertbol

## 2.0.0
* Added mandatory update
* Added new popups (ShowModalType) Page and BottomSheet
* Adding more customization options for the content dialog and bottomSheet
* Added more docs
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,40 @@ Customize the Alert Dialog
AppUpdateVersion.showAlertUpdate({
@required AppVersionResult? appVersionResult,
@required BuildContext? context,
String? title, = 'New version available',
String? content = 'Would you like to update your application?',
String? title = 'New version available',
String? content = ''Would you like to update your application?'',
String? cancelButtonText = 'Update later',
String? updateButtonText = 'Update',
ShowModalType? modalType = ShowModalType.alert_dialog,
ShowModalType? modalType = ShowModalType.alert_dialog, //anothers: page and bottom_sheet
Color? backgroundColor = Colors.white,
TextStyle? cancelTextStyle = const TextStyle(color: Colors.red),
TextStyle? updateTextStyle = const TextStyle(color: Colors.green),
TextStyle? titleTextStyle =
const TextStyle(fontSize: 18.0, fontWeight: FontWeight.w700),
TextStyle? contentTextStyle,
ButtonStyle? cancelButtonStyle,
ButtonStyle? updateButtonStyle,
TextStyle? titleTextStyle = const TextStyle(
fontSize: 20.0, fontWeight: FontWeight.w700, color: Colors.black),
ButtonStyle? cancelButtonStyle = const ButtonStyle(
overlayColor: MaterialStatePropertyAll(Colors.black12)),
ButtonStyle? updateButtonStyle = const ButtonStyle(
overlayColor: MaterialStatePropertyAll(Colors.black12),
),
})
// ShowModalType.page
// ShowModalType.bottom_sheet (available soon )
// ShowModalType.page (available soon )
```

## Additional information

| Next Updates | status |
|------------------------------|-------------|
| Mandatory or optional update | development |
| Mandatory or optional update | released |
| Create TestMode | development |
| Bottom sheet widget | development |
| Page widget | development |
| Bottom sheet widget | released |
| Page widget | released |
| Handle Exceptions | development |
| New options custom widgets | development |
| Automatic country detection | development |
| New options custom widgets | released |
| Automatic country detection | released |
| Modularize files | listed |

This project is at an initial level, more functions will be included as

Expand Down
171 changes: 117 additions & 54 deletions lib/app_version_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ library app_version_update;
import 'dart:convert';
import 'dart:io';
import 'package:app_version_update/core/functions/convert_version.dart';
import 'package:app_version_update/data/enums/app_version_widgets.dart';
import 'package:app_version_update/data/models/app_version_result.dart';
import 'package:app_version_update/widgets/alert_dialog_update.dart';
import 'package:app_version_update/widgets/bottom_sheet_update.dart';
import 'package:app_version_update/widgets/update_page.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -33,7 +34,6 @@ class AppVersionUpdate {
String? country = 'us',
}) async {
final packageInfo = await PackageInfo.fromPlatform();
if (Platform.isAndroid) {
playStoreId = playStoreId ?? packageInfo.packageName;
final parameters = {id: playStoreId, "hl": country};
Expand Down Expand Up @@ -94,65 +94,128 @@ class AppVersionUpdate {
/// * ```cancelTextStyle``` text style for text cancel button.
/// * ```updateButtonStyle``` style of update button.
/// * ```cancelButtonStyle``` style of cancel button.
/// * ```modalType``` not yet available, but it will serve as a decision for the type of widget provided by us for display.
/// * ```mandatory ``` for mandatories update default false
/// ## example
/// ```dart
/// await AppVersionUpdate.showAlertUpdate(
/// BuildContext? context,
/// AppVersionResult? appVersionResult,
/// bool? mandatory = false,
/// String? title = 'New version available',
/// TextStyle titleTextStyle =
/// const TextStyle(fontSize: 24.0, fontWeight: FontWeight.w500),
/// String? content = 'Would you like to update your application?',
/// TextStyle contentTextStyle =
/// const TextStyle(fontSize: 16.0, fontWeight: FontWeight.w400),
/// ButtonStyle? cancelButtonStyle = const ButtonStyle(
/// backgroundColor: MaterialStatePropertyAll(Colors.redAccent)),
/// ButtonStyle? updateButtonStyle = const ButtonStyle(
/// backgroundColor: MaterialStatePropertyAll(Colors.green)),
/// String? cancelButtonText = 'UPDATE LATER',
/// String? updateButtonText = 'UPDATE',
/// TextStyle? cancelTextStyle = const TextStyle(color: Colors.white),
/// TextStyle? updateTextStyle = const TextStyle(color: Colors.white),
/// Color? backgroundColor = Colors.white
/// );
/// ```
static showAlertUpdate(
{BuildContext? context,
AppVersionResult? appVersionResult,
bool? mandatory = false,
String? title = 'New version available',
TextStyle titleTextStyle =
const TextStyle(fontSize: 24.0, fontWeight: FontWeight.w500),
String? content = 'Would you like to update your application?',
TextStyle contentTextStyle =
const TextStyle(fontSize: 16.0, fontWeight: FontWeight.w400),
ButtonStyle? cancelButtonStyle = const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.redAccent)),
ButtonStyle? updateButtonStyle = const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.green)),
String? cancelButtonText = 'UPDATE LATER',
String? updateButtonText = 'UPDATE',
TextStyle? cancelTextStyle = const TextStyle(color: Colors.white),
TextStyle? updateTextStyle = const TextStyle(color: Colors.white),
Color? backgroundColor = Colors.white}) async {
await showDialog(
barrierDismissible: !mandatory!,
context: context!,
builder: (context) => UpdateVersionDialog(
appVersionResult: appVersionResult,
backgroundColor: backgroundColor,
cancelButtonStyle: cancelButtonStyle,
cancelButtonText: cancelButtonText,
cancelTextStyle: cancelTextStyle,
content: content,
contentTextStyle: contentTextStyle,
title: title,
titleTextStyle: titleTextStyle,
mandatory: mandatory,
updateButtonStyle: updateButtonStyle,
updateButtonText: updateButtonText,
updateTextStyle: updateTextStyle,
));
}
/// Used for This widget comstujma be used for updates that have terms to accept or explanations
/// Navigate to another page, just pass your widget that will open as a page
/// * ```appVersionResult``` result of [AppVersionUpdate.checkForUpdate()].
/// * ```context``` build context.
/// * ```page``` your custom page for displays update or default page in use
/// * ```mandatory ``` for mandatories update default false
/// ## example
/// ```dart
/// await AppVersionUpdate.showPageUpdate(
/// appVersionResult: data,
/// context: context,
/// backgroundColor: Colors.red,
/// title: 'Title.',
/// content:
/// 'Body content',
/// updateButtonText: 'UPDATE',
/// cancelButtonText: 'UPDATE LATER',
/// titleTextStyle: TextStyle(color: Colors.black, fontSize: 16.0),
/// contentTextStyle: TextStyle(color: Colors.black),
/// page: MyCustomPAge()
/// );
/// ```
static showAlertUpdate({
@required AppVersionResult? appVersionResult,
@required BuildContext? context,
String? title = 'New version available',
String? content = 'Would you like to update your application?',
String? cancelButtonText = 'Update later',
String? updateButtonText = 'Update',
ShowModalType? modalType = ShowModalType.alert_dialog,
Color? backgroundColor = Colors.white,
TextStyle? cancelTextStyle = const TextStyle(color: Colors.red),
TextStyle? updateTextStyle = const TextStyle(color: Colors.green),
TextStyle? titleTextStyle =
const TextStyle(fontSize: 20.0, fontWeight: FontWeight.w700),
TextStyle? contentTextStyle,
ButtonStyle? cancelButtonStyle,
ButtonStyle? updateButtonStyle,
}) async {
if (modalType == ShowModalType.alert_dialog) {
await showDialog(
context: context!,
builder: (context) => UpdateVersionDialog(
appVersionResult: appVersionResult,
title: title,
titleTextStyle: titleTextStyle,
content: content,
cancelTextStyle: cancelTextStyle,
updateTextStyle: updateTextStyle,
contentTextStyle: contentTextStyle,
backgroundColor: backgroundColor,
cancelButtonText: cancelButtonText,
cancelButtonStyle: cancelButtonStyle,
updateButtonText: updateButtonText,
updateButtonStyle: updateButtonStyle,
));
} else if (modalType == ShowModalType.page) {
throw "available soon";
// Navigator.push(context!,
// MaterialPageRoute(builder: (context) => const UpdateVersionPage()));
} else if (modalType == ShowModalType.bottom_sheet) {
throw "available soon";
}
static showPageUpdate(
{@required BuildContext? context,
@required AppVersionResult? appVersionResult,
bool? mandatory = false,
Widget? page}) async {
Navigator.push(
context!,
MaterialPageRoute(
builder: (context) =>
page ??
UpdateVersionPage(
mandatory: mandatory,
appVersionResult: appVersionResult,
)));
}
static showBottomSheetUpdate() async {}
static showPageUpdate() async {}
/// Opens a bottomsheet, with title, content and update options
/// * ```appVersionResult``` result of [AppVersionUpdate.checkForUpdate()].
/// * ```context``` build context.
/// * ```page``` your custom page for displays update or default page in use
/// * ```title``` text title
/// * ```mandatory ``` for mandatories update default false
/// ## example
/// ```dart
/// await AppVersionUpdate.showBottomSheetUpdate(
/// appVersionResult: data,
/// context: context,
/// content: WidgetWithContent() or use default,
/// title: text title bottomSheet or default
/// );
/// ```
static showBottomSheetUpdate(
{@required BuildContext? context,
@required AppVersionResult? appVersionResult,
bool? mandatory = false,
String? title = 'New version avaible',
Widget? content}) async {
await showModalBottomSheet(
isDismissible: !mandatory!,
context: context!,
builder: (context) => BottomSheetUpdateVersion(
appVersionResult: appVersionResult,
mandatory: mandatory,
content: content,
title: title,
));
}
}
Loading

0 comments on commit 9a97701

Please sign in to comment.