From fcd23e78b6a296949378f28bb884213232d341bd Mon Sep 17 00:00:00 2001 From: mike doornenbal Date: Wed, 7 Feb 2024 14:57:31 +0100 Subject: [PATCH] fix: add CI and linter --- .github/workflows/component-ci.yml | 14 ++ CHANGELOG.md | 4 + analysis_options.yaml | 11 +- lib/flutter_dialogs.dart | 8 +- lib/src/alert_dialogs.dart | 370 ++++++++++++++--------------- lib/src/dialogs.dart | 12 +- lib/src/popup.dart | 9 +- lib/src/popup_parent.dart | 56 +++-- lib/src/popup_service.dart | 28 ++- pubspec.yaml | 9 +- 10 files changed, 269 insertions(+), 252 deletions(-) create mode 100644 .github/workflows/component-ci.yml diff --git a/.github/workflows/component-ci.yml b/.github/workflows/component-ci.yml new file mode 100644 index 0000000..ca69d49 --- /dev/null +++ b/.github/workflows/component-ci.yml @@ -0,0 +1,14 @@ +name: Iconica Standard Component CI Workflow +# Workflow Caller version: 2.0.0 + +on: + pull_request: + workflow_dispatch: + +jobs: + call-global-iconica-workflow: + uses: Iconica-Development/.github/.github/workflows/component-ci.yml@master + secrets: inherit + permissions: write-all + with: + subfolder: "." # add optional subfolder to run workflow in diff --git a/CHANGELOG.md b/CHANGELOG.md index 6172925..fef9865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.2 + +- Added CI and linter + ## 0.0.1 - Initial port diff --git a/analysis_options.yaml b/analysis_options.yaml index a5744c1..e2b30bf 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,9 @@ -include: package:flutter_lints/flutter.yaml +include: package:flutter_iconica_analysis/analysis_options.yaml -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +# Possible to overwrite the rules from the package + +analyzer: + exclude: + +linter: + rules: \ No newline at end of file diff --git a/lib/flutter_dialogs.dart b/lib/flutter_dialogs.dart index 2b32599..843a5f1 100644 --- a/lib/flutter_dialogs.dart +++ b/lib/flutter_dialogs.dart @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2022 Iconica // // SPDX-License-Identifier: BSD-3-Clause - +/// library flutter_dialogs; -export './src/dialogs.dart'; -export './src/popup_service.dart'; -export './src/popup_parent.dart'; export './src/alert_dialogs.dart'; +export './src/dialogs.dart'; +export './src/popup_parent.dart'; +export './src/popup_service.dart'; diff --git a/lib/src/alert_dialogs.dart b/lib/src/alert_dialogs.dart index 469ef59..984c856 100644 --- a/lib/src/alert_dialogs.dart +++ b/lib/src/alert_dialogs.dart @@ -5,20 +5,19 @@ import 'package:flutter/material.dart'; class AlertDialogAction { - final String text; - final bool primary; - final bool secondary; - final VoidCallback onPressed; - AlertDialogAction({ required this.text, + required this.onPressed, this.primary = false, this.secondary = false, - required this.onPressed, }) : assert( !(primary && secondary), "AlertDialogAction can't be primary and secondary at the same time", ); + final String text; + final bool primary; + final bool secondary; + final VoidCallback onPressed; } typedef ButtonCallback = Widget Function( @@ -33,13 +32,6 @@ typedef IconButtonCallback = Widget Function( ); class IconicaAlertDialog extends StatelessWidget { - final List buttons; - final WidgetBuilder body; - final bool? closeButton; - final ButtonCallback? primaryButton; - final ButtonCallback? secondaryButton; - final IconButtonCallback? iconButton; - const IconicaAlertDialog._({ required this.buttons, required this.body, @@ -59,23 +51,22 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog.multiButton( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - title: title, - body: body, - buttons: [ - AlertDialogAction( - text: buttonText, - onPressed: onPressed, - primary: primary, - ), - ], - ); - } + }) => + IconicaAlertDialog.multiButton( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + title: title, + body: body, + buttons: [ + AlertDialogAction( + text: buttonText, + onPressed: onPressed, + primary: primary, + ), + ], + ); factory IconicaAlertDialog.multiButton({ required String title, @@ -85,40 +76,39 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog._( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - buttons: buttons, - body: (context) => Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20, + }) => + IconicaAlertDialog._( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + buttons: buttons, + body: (context) => Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 20, + ), + child: Text( + title, + style: Theme.of(context).textTheme.titleLarge?.copyWith( + fontWeight: FontWeight.bold, + color: Theme.of(context).textTheme.bodyMedium?.color, + ), + textAlign: TextAlign.center, + ), ), - child: Text( - title, - style: Theme.of(context).textTheme.headline6?.copyWith( - fontWeight: FontWeight.bold, - color: Theme.of(context).textTheme.bodyText2?.color, - ), - textAlign: TextAlign.center, + Padding( + padding: const EdgeInsets.only(top: 20, left: 20, right: 20), + child: Text( + body, + style: Theme.of(context).textTheme.bodyMedium, + textAlign: TextAlign.center, + ), ), - ), - Padding( - padding: const EdgeInsets.only(top: 20, left: 20, right: 20), - child: Text( - body, - style: Theme.of(context).textTheme.bodyText2, - textAlign: TextAlign.center, - ), - ), - ], - ), - ); - } + ], + ), + ); factory IconicaAlertDialog.icon({ required String title, @@ -129,38 +119,37 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog._( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - buttons: buttons, - body: (context) => Column( - children: [ - icon, - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Text( - title, - style: Theme.of(context).textTheme.headline6?.copyWith( - fontWeight: FontWeight.bold, - ), - textAlign: TextAlign.center, + }) => + IconicaAlertDialog._( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + buttons: buttons, + body: (context) => Column( + children: [ + icon, + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Text( + title, + style: Theme.of(context).textTheme.titleLarge?.copyWith( + fontWeight: FontWeight.bold, + ), + textAlign: TextAlign.center, + ), ), - ), - Padding( - padding: const EdgeInsets.only(top: 20, left: 20, right: 20), - child: Text( - body, - style: Theme.of(context).textTheme.bodyText2, - textAlign: TextAlign.center, + Padding( + padding: const EdgeInsets.only(top: 20, left: 20, right: 20), + child: Text( + body, + style: Theme.of(context).textTheme.bodyMedium, + textAlign: TextAlign.center, + ), ), - ), - ], - ), - ); - } + ], + ), + ); factory IconicaAlertDialog.yesOrNo({ required String title, @@ -173,17 +162,16 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog.multiButton( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - title: title, - body: body, - buttons: _getYesNoDialogButtons(focusYes, otherSecondary, onYes, onNo), - ); - } + }) => + IconicaAlertDialog.multiButton( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + title: title, + body: body, + buttons: _getYesNoDialogButtons(focusYes, otherSecondary, onYes, onNo), + ); factory IconicaAlertDialog.yesOrNoIcon({ required String title, @@ -197,18 +185,17 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog.icon( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - title: title, - body: body, - icon: icon, - buttons: _getYesNoDialogButtons(focusYes, otherSecondary, onYes, onNo), - ); - } + }) => + IconicaAlertDialog.icon( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + title: title, + body: body, + icon: icon, + buttons: _getYesNoDialogButtons(focusYes, otherSecondary, onYes, onNo), + ); factory IconicaAlertDialog.singleButtonIcon({ required String title, @@ -222,25 +209,24 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog.icon( - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - closeButton: closeButton, - title: title, - icon: icon, - body: body, - buttons: [ - AlertDialogAction( - text: buttonText, - primary: primary, - secondary: secondary, - onPressed: onPressed, - ), - ], - ); - } + }) => + IconicaAlertDialog.icon( + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + closeButton: closeButton, + title: title, + icon: icon, + body: body, + buttons: [ + AlertDialogAction( + text: buttonText, + primary: primary, + secondary: secondary, + onPressed: onPressed, + ), + ], + ); factory IconicaAlertDialog.custom({ required Widget body, @@ -249,16 +235,21 @@ class IconicaAlertDialog extends StatelessWidget { ButtonCallback? primaryButton, ButtonCallback? secondaryButton, IconButtonCallback? iconButton, - }) { - return IconicaAlertDialog._( - closeButton: closeButton, - buttons: buttons, - body: (_) => body, - primaryButton: primaryButton, - secondaryButton: secondaryButton, - iconButton: iconButton, - ); - } + }) => + IconicaAlertDialog._( + closeButton: closeButton, + buttons: buttons, + body: (_) => body, + primaryButton: primaryButton, + secondaryButton: secondaryButton, + iconButton: iconButton, + ); + final List buttons; + final WidgetBuilder body; + final bool? closeButton; + final ButtonCallback? primaryButton; + final ButtonCallback? secondaryButton; + final IconButtonCallback? iconButton; static List _getYesNoDialogButtons( bool focusYes, @@ -267,49 +258,47 @@ class IconicaAlertDialog extends StatelessWidget { VoidCallback onNo, { String no = 'No', String yes = 'Yes', - }) { - return [ - if (focusYes) ...[ + }) => + [ + if (focusYes) ...[ + AlertDialogAction( + text: no, + primary: !focusYes, + secondary: !focusYes && otherSecondary, + onPressed: onNo, + ), + ], AlertDialogAction( - text: no, - primary: !focusYes, + text: yes, + primary: focusYes, secondary: !focusYes && otherSecondary, - onPressed: onNo, + onPressed: onYes, ), - ], - AlertDialogAction( - text: yes, - primary: focusYes, - secondary: !focusYes && otherSecondary, - onPressed: onYes, - ), - if (!focusYes) ...[ - AlertDialogAction( - text: no, - primary: !focusYes, - secondary: focusYes && otherSecondary, - onPressed: onNo, - ), - ], - ]; - } + if (!focusYes) ...[ + AlertDialogAction( + text: no, + primary: !focusYes, + secondary: focusYes && otherSecondary, + onPressed: onNo, + ), + ], + ]; @override - Widget build(BuildContext context) { - return Column( - children: [ - const Spacer(), - AlertDialog( - insetPadding: EdgeInsets.zero, - contentPadding: EdgeInsets.zero, - backgroundColor: Theme.of(context).cardColor, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(10), - topRight: Radius.circular(10), + Widget build(BuildContext context) => Column( + children: [ + const Spacer(), + AlertDialog( + insetPadding: EdgeInsets.zero, + contentPadding: EdgeInsets.zero, + backgroundColor: Theme.of(context).cardColor, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(10), + topRight: Radius.circular(10), + ), ), - ), - content: SizedBox( + content: SizedBox( width: MediaQuery.of(context).size.width, child: Stack( children: [ @@ -322,10 +311,11 @@ class IconicaAlertDialog extends StatelessWidget { body.call(context), Padding( padding: EdgeInsets.only( - top: buttons.isNotEmpty ? 40 : 0, - bottom: 20, - left: 20, - right: 20), + top: buttons.isNotEmpty ? 40 : 0, + bottom: 20, + left: 20, + right: 20, + ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: buttons.map( @@ -377,9 +367,9 @@ class IconicaAlertDialog extends StatelessWidget { ), ], ], - )), - ) - ], - ); - } + ), + ), + ), + ], + ); } diff --git a/lib/src/dialogs.dart b/lib/src/dialogs.dart index 4521add..9121d7e 100644 --- a/lib/src/dialogs.dart +++ b/lib/src/dialogs.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart' as m; class DialogService { static DialogService? _instance; - static DialogService get instance => _instance ??= DialogService(); + static final DialogService instance = _instance ??= DialogService(); Future showDialog({ required m.BuildContext context, @@ -17,16 +17,14 @@ class DialogService { bool useSafeArea = false, bool useRootNavigator = true, m.RouteSettings? routeSettings, - }) { - return m.showDialog( + }) => + m.showDialog( context: context, barrierDismissible: barrierDismissible, barrierColor: barrierColor, barrierLabel: barrierLabel, useSafeArea: useSafeArea, useRootNavigator: useRootNavigator, - builder: (ctx) { - return m.Builder(builder: builder); - }); - } + builder: (ctx) => m.Builder(builder: builder), + ); } diff --git a/lib/src/popup.dart b/lib/src/popup.dart index e805667..5ac8879 100644 --- a/lib/src/popup.dart +++ b/lib/src/popup.dart @@ -9,16 +9,17 @@ class PopUp extends StatelessWidget { const PopUp({ required this.popUpData, this.onTap, - Key? key, - }) : super(key: key); + super.key, + }); final void Function()? onTap; final PopUpData popUpData; @override Widget build(BuildContext context) { - var style = Theme.of(context).textTheme.bodyText1?.copyWith( - color: popUpData.textColor ?? Theme.of(context).backgroundColor, + var style = Theme.of(context).textTheme.bodyLarge?.copyWith( + color: + popUpData.textColor ?? Theme.of(context).colorScheme.background, fontWeight: FontWeight.w500, fontSize: 14, height: 1.571, diff --git a/lib/src/popup_parent.dart b/lib/src/popup_parent.dart index 67288d6..63eb472 100644 --- a/lib/src/popup_parent.dart +++ b/lib/src/popup_parent.dart @@ -10,7 +10,7 @@ import 'package:flutter_dialogs/src/popup_data.dart'; import 'package:flutter_dialogs/src/popup_service.dart'; class PopUpParent extends StatefulWidget { - const PopUpParent({required this.child, Key? key}) : super(key: key); + const PopUpParent({required this.child, super.key}); final Widget child; @@ -26,7 +26,7 @@ class PopUpParentState extends State { final Queue _popUpQueue = Queue(); void displayPopUp(PopUpData popUp) { - if (_showPopUp == true) { + if (_showPopUp) { _popUpQueue.add(popUp); return; } @@ -62,33 +62,31 @@ class PopUpParentState extends State { } @override - Widget build(BuildContext context) { - return Stack( - children: [ - widget.child, - Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height - - MediaQuery.of(context).viewInsets.bottom, - alignment: Alignment.bottomCenter, - child: AnimatedCrossFade( - firstChild: SizedBox( - width: MediaQuery.of(context).size.width, + Widget build(BuildContext context) => Stack( + children: [ + widget.child, + Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height - + MediaQuery.of(context).viewInsets.bottom, + alignment: Alignment.bottomCenter, + child: AnimatedCrossFade( + firstChild: SizedBox( + width: MediaQuery.of(context).size.width, + ), + secondChild: _popUp?.custom ?? + PopUp( + popUpData: _popUp ?? PopUpData(const Duration(seconds: 3)), + onTap: () { + _closePopUp(_popUpId); + }, + ), + crossFadeState: _showPopUp + ? CrossFadeState.showSecond + : CrossFadeState.showFirst, + duration: const Duration(milliseconds: 250), ), - secondChild: _popUp?.custom ?? - PopUp( - popUpData: _popUp ?? PopUpData(const Duration(seconds: 3)), - onTap: () { - _closePopUp(_popUpId); - }, - ), - crossFadeState: _showPopUp - ? CrossFadeState.showSecond - : CrossFadeState.showFirst, - duration: const Duration(milliseconds: 250), ), - ), - ], - ); - } + ], + ); } diff --git a/lib/src/popup_service.dart b/lib/src/popup_service.dart index dd73ba5..1548bee 100644 --- a/lib/src/popup_service.dart +++ b/lib/src/popup_service.dart @@ -8,7 +8,7 @@ import 'package:flutter_dialogs/src/popup_parent.dart'; class PopUpService { static PopUpService? _instance; - static PopUpService get instance => _instance ??= PopUpService(); + static final PopUpService instance = _instance ??= PopUpService(); late PopUpParentState currentState; @@ -19,22 +19,26 @@ class PopUpService { Color? backgroundColor, Color? textColor, }) { - currentState.displayPopUp(PopUpData( - duration, - text: text, - icon: icon, - backgroundColor: backgroundColor, - textColor: textColor, - )); + currentState.displayPopUp( + PopUpData( + duration, + text: text, + icon: icon, + backgroundColor: backgroundColor, + textColor: textColor, + ), + ); } void showCustom( Widget custom, { Duration duration = const Duration(seconds: 3), }) { - currentState.displayPopUp(PopUpData( - duration, - custom: custom, - )); + currentState.displayPopUp( + PopUpData( + duration, + custom: custom, + ), + ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 818cc03..c500562 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: flutter_dialogs description: A new Flutter package project. -version: 0.0.1 +version: 0.0.2 homepage: https://github.com/Iconica-Development/flutter_dialogs environment: - sdk: '>=2.18.2 <3.0.0' + sdk: ">=2.18.2 <3.0.0" flutter: ">=1.17.0" dependencies: @@ -14,6 +14,9 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_iconica_analysis: + git: + url: https://github.com/Iconica-Development/flutter_iconica_analysis + ref: 6.0.0 flutter: