From 42e20b406e8b9c46afb3e36dc3d3b2f835e62a8b Mon Sep 17 00:00:00 2001 From: Przemek Date: Wed, 20 Dec 2023 10:21:15 +0100 Subject: [PATCH 1/5] Remove WillPopScope --- lib/src/widgets/reactive_form.dart | 18 +----------------- lib/src/widgets/reactive_form_builder.dart | 14 -------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/lib/src/widgets/reactive_form.dart b/lib/src/widgets/reactive_form.dart index 0dc19e5..78cf3a8 100644 --- a/lib/src/widgets/reactive_form.dart +++ b/lib/src/widgets/reactive_form.dart @@ -18,18 +18,6 @@ class ReactiveForm extends StatelessWidget { /// The form group control that is bound to this widget. final FormGroup formGroup; - /// Enables the form to veto attempts by the user to dismiss the [ModalRoute] - /// that contains the form. - /// - /// If the callback returns a Future that resolves to false, the form's route - /// will not be popped. - /// - /// See also: - /// - /// * [WillPopScope], another widget that provides a way to intercept the - /// back button. - final WillPopCallback? onWillPop; - /// Creates and instance of [ReactiveForm]. /// /// The [formGroup] and [child] arguments are required. @@ -37,7 +25,6 @@ class ReactiveForm extends StatelessWidget { Key? key, required this.formGroup, required this.child, - this.onWillPop, }) : super(key: key); /// Returns the nearest model up its widget tree. @@ -67,10 +54,7 @@ class ReactiveForm extends StatelessWidget { return FormControlInheritedStreamer( control: formGroup, stream: formGroup.statusChanged, - child: WillPopScope( - onWillPop: onWillPop, - child: child, - ), + child: child, ); } } diff --git a/lib/src/widgets/reactive_form_builder.dart b/lib/src/widgets/reactive_form_builder.dart index 3098a2d..1158fc7 100644 --- a/lib/src/widgets/reactive_form_builder.dart +++ b/lib/src/widgets/reactive_form_builder.dart @@ -24,18 +24,6 @@ class ReactiveFormBuilder extends StatefulWidget { /// The widget below this widget in the tree. final Widget? child; - /// Enables the form to veto attempts by the user to dismiss the [ModalRoute] - /// that contains the form. - /// - /// If the callback returns a Future that resolves to false, the form's route - /// will not be popped. - /// - /// See also: - /// - /// * [WillPopScope], another widget that provides a way to intercept the - /// back button. - final WillPopCallback? onWillPop; - /// Creates and instance of [ReactiveFormBuilder]. /// /// The [form] and [builder] arguments must not be null. @@ -59,7 +47,6 @@ class ReactiveFormBuilder extends StatefulWidget { const ReactiveFormBuilder({ Key? key, this.child, - this.onWillPop, required this.form, required this.builder, }) : super(key: key); @@ -81,7 +68,6 @@ class ReactiveFormBuilderState extends State { Widget build(BuildContext context) { return ReactiveForm( formGroup: _form, - onWillPop: widget.onWillPop, child: widget.builder(context, _form, widget.child), ); } From a9b376f1de1ce913d396241853abe7b1f47613b8 Mon Sep 17 00:00:00 2001 From: Przemek Date: Sun, 28 Jan 2024 12:49:07 +0100 Subject: [PATCH 2/5] Added ReactiveFormPopScope widget --- lib/src/widgets/reactive_form.dart | 17 ++++++++++- lib/src/widgets/reactive_form_builder.dart | 20 +++++++++++-- lib/src/widgets/reactive_form_pop_scope.dart | 30 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 lib/src/widgets/reactive_form_pop_scope.dart diff --git a/lib/src/widgets/reactive_form.dart b/lib/src/widgets/reactive_form.dart index 78cf3a8..979f3a2 100644 --- a/lib/src/widgets/reactive_form.dart +++ b/lib/src/widgets/reactive_form.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:reactive_forms/reactive_forms.dart'; import 'package:reactive_forms/src/widgets/form_control_inherited_notifier.dart'; +import 'package:reactive_forms/src/widgets/reactive_form_pop_scope.dart'; /// This class is responsible for create a [FormControlInheritedStreamer] for /// exposing a [FormGroup] to all descendants widgets. @@ -18,6 +19,12 @@ class ReactiveForm extends StatelessWidget { /// The form group control that is bound to this widget. final FormGroup formGroup; + /// Determine whether a route can popped. See [PopScope] for more details. + final bool Function(FormGroup formGroup)? canPop; + + /// A callback invoked when a route is popped. See [PopScope] for more details. + final void Function(FormGroup formGroup, bool didPop)? onPopInvoked; + /// Creates and instance of [ReactiveForm]. /// /// The [formGroup] and [child] arguments are required. @@ -25,6 +32,8 @@ class ReactiveForm extends StatelessWidget { Key? key, required this.formGroup, required this.child, + this.canPop, + this.onPopInvoked, }) : super(key: key); /// Returns the nearest model up its widget tree. @@ -54,7 +63,13 @@ class ReactiveForm extends StatelessWidget { return FormControlInheritedStreamer( control: formGroup, stream: formGroup.statusChanged, - child: child, + child: canPop != null || onPopInvoked != null + ? ReactiveFormPopScope( + canPop: canPop, + onPopInvoked: onPopInvoked, + child: child, + ) + : child, ); } } diff --git a/lib/src/widgets/reactive_form_builder.dart b/lib/src/widgets/reactive_form_builder.dart index 1158fc7..ba30048 100644 --- a/lib/src/widgets/reactive_form_builder.dart +++ b/lib/src/widgets/reactive_form_builder.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:reactive_forms/reactive_forms.dart'; import 'package:reactive_forms/src/widgets/form_control_inherited_notifier.dart'; +import 'package:reactive_forms/src/widgets/reactive_form_pop_scope.dart'; /// FormGroup builder function definition of the [ReactiveFormBuilder]. typedef ReactiveFormBuilderCreator = FormGroup Function(); @@ -21,6 +22,12 @@ class ReactiveFormBuilder extends StatefulWidget { /// Called to create the FormGroup that will be bind to this widget. final ReactiveFormBuilderCreator form; + /// Determine whether a route can popped. See [PopScope] for more details. + final bool Function(FormGroup formGroup)? canPop; + + /// A callback invoked when a route is popped. See [PopScope] for more details. + final void Function(FormGroup formGroup, bool didPop)? onPopInvoked; + /// The widget below this widget in the tree. final Widget? child; @@ -46,9 +53,11 @@ class ReactiveFormBuilder extends StatefulWidget { /// ``` const ReactiveFormBuilder({ Key? key, - this.child, required this.form, required this.builder, + this.canPop, + this.onPopInvoked, + this.child, }) : super(key: key); @override @@ -66,9 +75,16 @@ class ReactiveFormBuilderState extends State { @override Widget build(BuildContext context) { + final child = widget.builder(context, _form, widget.child); return ReactiveForm( formGroup: _form, - child: widget.builder(context, _form, widget.child), + child: widget.canPop != null || widget.onPopInvoked != null + ? ReactiveFormPopScope( + canPop: widget.canPop, + onPopInvoked: widget.onPopInvoked, + child: child, + ) + : child, ); } } diff --git a/lib/src/widgets/reactive_form_pop_scope.dart b/lib/src/widgets/reactive_form_pop_scope.dart new file mode 100644 index 0000000..51f9b1c --- /dev/null +++ b/lib/src/widgets/reactive_form_pop_scope.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:reactive_forms/reactive_forms.dart'; + +class ReactiveFormPopScope extends StatelessWidget { + final bool Function(FormGroup formGroup)? canPop; + final void Function(FormGroup formGroup, bool didPop)? onPopInvoked; + final Widget child; + + const ReactiveFormPopScope({ + super.key, + this.canPop, + this.onPopInvoked, + required this.child, + }); + + @override + Widget build(BuildContext context) { + return ReactiveFormConsumer( + builder: (context, formGroup, _) { + return PopScope( + canPop: canPop != null ? canPop!(formGroup) : true, + onPopInvoked: onPopInvoked != null + ? (didPop) => onPopInvoked!(formGroup, didPop) + : null, + child: child, + ); + }, + ); + } +} From c45f2c28def9bd54a5d5b862c9f554080fc1a21c Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 30 Jan 2024 19:49:58 +0100 Subject: [PATCH 3/5] Remove redudant ReactiveFormPopScope --- lib/src/widgets/reactive_form_builder.dart | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/src/widgets/reactive_form_builder.dart b/lib/src/widgets/reactive_form_builder.dart index ba30048..d191387 100644 --- a/lib/src/widgets/reactive_form_builder.dart +++ b/lib/src/widgets/reactive_form_builder.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:reactive_forms/reactive_forms.dart'; import 'package:reactive_forms/src/widgets/form_control_inherited_notifier.dart'; -import 'package:reactive_forms/src/widgets/reactive_form_pop_scope.dart'; /// FormGroup builder function definition of the [ReactiveFormBuilder]. typedef ReactiveFormBuilderCreator = FormGroup Function(); @@ -75,16 +74,11 @@ class ReactiveFormBuilderState extends State { @override Widget build(BuildContext context) { - final child = widget.builder(context, _form, widget.child); return ReactiveForm( formGroup: _form, - child: widget.canPop != null || widget.onPopInvoked != null - ? ReactiveFormPopScope( - canPop: widget.canPop, - onPopInvoked: widget.onPopInvoked, - child: child, - ) - : child, + canPop: widget.canPop, + onPopInvoked: widget.onPopInvoked, + child: widget.builder(context, _form, widget.child), ); } } From 84027512a307b5aa3ddaab8c855c7d82e0b803d1 Mon Sep 17 00:00:00 2001 From: Przemek Date: Sun, 10 Mar 2024 09:32:35 +0100 Subject: [PATCH 4/5] update changelog and pubspec --- CHANGELOG.md | 10 ++++++++++ pubspec.yaml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4276b5..0beb7c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 17.0.0 + +## Breaking changes + +- Remove `onWillPop` from `ReactiveForm` and `ReactiveFormBuilder` widgets. + +## Features + +- Add `canPop` and `onPopInvoked` to `ReactiveForm` and `ReactiveFormBuilder` widgets. + # 16.1.1 ## Fixes diff --git a/pubspec.yaml b/pubspec.yaml index 9977232..550638e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: reactive_forms description: This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular Reactive Forms. -version: 16.1.1 +version: 17.0.0 homepage: "https://github.com/joanpablo/reactive_forms" environment: From 0568710f4517b497676384b626c2718c678676ba Mon Sep 17 00:00:00 2001 From: Joan Pablo Date: Fri, 29 Mar 2024 11:00:29 -0400 Subject: [PATCH 5/5] Update reactive_forms.yaml Add Flutter 3.16.0 to cli --- .github/workflows/reactive_forms.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reactive_forms.yaml b/.github/workflows/reactive_forms.yaml index a99023f..838c900 100644 --- a/.github/workflows/reactive_forms.yaml +++ b/.github/workflows/reactive_forms.yaml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - uses: subosito/flutter-action@v2 with: - flutter-version: "3.10.0" + flutter-version: "3.16.0" channel: "stable" - run: flutter pub get - run: flutter test --no-pub --coverage @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v3 - uses: subosito/flutter-action@v2 with: - flutter-version: "3.10.0" + flutter-version: "3.16.0" channel: "stable" - run: flutter pub get - name: Analyze lib @@ -51,7 +51,7 @@ jobs: - uses: actions/checkout@v3 - uses: subosito/flutter-action@v2 with: - flutter-version: "3.10.0" + flutter-version: "3.16.0" channel: "stable" - run: flutter pub get - name: Format lib