mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-18 13:13:44 +02:00
feat(bool): Add a boolean field. Can be used for accepting terms and conditions
This commit is contained in:
parent
d1ad003c22
commit
46e2d960af
9 changed files with 148 additions and 28 deletions
|
@ -26,6 +26,6 @@ subprojects {
|
|||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
|
|
@ -2,27 +2,83 @@
|
|||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_registration/flutter_registration.dart';
|
||||
import 'example_registration_repository.dart';
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
const MaterialApp(
|
||||
home: FlutterRegistrationDemo(),
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
inputDecorationTheme: const InputDecorationTheme(
|
||||
errorStyle: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
home: const FlutterRegistrationDemo(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class FlutterRegistrationDemo extends StatelessWidget {
|
||||
class FlutterRegistrationDemo extends StatefulWidget {
|
||||
const FlutterRegistrationDemo({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FlutterRegistrationDemo> createState() =>
|
||||
_FlutterRegistrationDemoState();
|
||||
}
|
||||
|
||||
class _FlutterRegistrationDemoState extends State<FlutterRegistrationDemo> {
|
||||
late List<AuthStep> steps;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
steps = RegistrationOptions.getDefaultSteps();
|
||||
|
||||
steps[1].fields.add(
|
||||
AuthBoolField(
|
||||
name: 'termsConditions',
|
||||
widgetType: BoolWidgetType.checkbox,
|
||||
validators: [
|
||||
(value) {
|
||||
if (value == null || !value) {
|
||||
return 'Required';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
],
|
||||
rightWidget: Text.rich(
|
||||
TextSpan(
|
||||
text: 'I agree with the ',
|
||||
// style: const TextStyle(fontSize: 16, color: Colors.black),
|
||||
children: <TextSpan>[
|
||||
TextSpan(
|
||||
text: 'terms & conditions',
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
debugPrint('Open terms and conditions');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RegistrationScreen(
|
||||
registrationOptions: RegistrationOptions(
|
||||
previousButtonBuilder: (onPressed, label) => null,
|
||||
registrationRepository: ExampleRegistrationRepository(),
|
||||
registrationSteps: RegistrationOptions.getDefaultSteps(),
|
||||
registrationSteps: steps,
|
||||
afterRegistration: () {
|
||||
debugPrint('Registered!');
|
||||
},
|
||||
|
|
|
@ -37,10 +37,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
|
||||
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.2"
|
||||
version: "1.18.0"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -62,6 +62,13 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_input_library:
|
||||
dependency: transitive
|
||||
description:
|
||||
path: "../../flutter_input_library"
|
||||
relative: true
|
||||
source: path
|
||||
version: "2.7.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
@ -81,7 +88,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.5.0"
|
||||
version: "1.2.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
@ -123,10 +130,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
|
||||
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
version: "1.10.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -152,18 +159,18 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
|
||||
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
version: "1.11.1"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
|
||||
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -184,10 +191,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
|
||||
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
version: "0.6.1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -200,10 +207,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
|
||||
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.4-beta"
|
||||
version: "0.3.0"
|
||||
sdks:
|
||||
dart: ">=3.1.0-185.0.dev <4.0.0"
|
||||
dart: ">=3.2.0-194.0.dev <4.0.0"
|
||||
flutter: ">=1.17.0"
|
||||
|
|
|
@ -10,5 +10,8 @@ export 'src/model/auth_exception.dart';
|
|||
export 'src/model/auth_field.dart';
|
||||
export 'src/model/auth_step.dart';
|
||||
export 'src/model/auth_text_field.dart';
|
||||
export 'src/model/auth_bool_field.dart';
|
||||
export 'src/registration_screen.dart';
|
||||
export 'src/service/registration_repository.dart';
|
||||
export 'package:flutter_input_library/flutter_input_library.dart'
|
||||
show BoolWidgetType;
|
||||
|
|
|
@ -24,7 +24,7 @@ class AuthScreen extends StatefulWidget {
|
|||
|
||||
final String title;
|
||||
final Future<void> Function({
|
||||
required HashMap<String, String> values,
|
||||
required HashMap<String, dynamic> values,
|
||||
required void Function(int? pageToReturn) onError,
|
||||
}) onFinish;
|
||||
final List<AuthStep> steps;
|
||||
|
@ -69,12 +69,11 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||
FocusScope.of(context).unfocus();
|
||||
|
||||
if (widget.steps.last == step) {
|
||||
var values = HashMap<String, String>();
|
||||
var values = HashMap<String, dynamic>();
|
||||
|
||||
for (var step in widget.steps) {
|
||||
for (var field in step.fields) {
|
||||
values[field.name] =
|
||||
(field as AuthTextField).textController.value.text;
|
||||
values[field.name] = field.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
47
lib/src/model/auth_bool_field.dart
Normal file
47
lib/src/model/auth_bool_field.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
// SPDX-FileCopyrightText: 2022 Iconica
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_input_library/flutter_input_library.dart';
|
||||
import 'package:flutter_registration/flutter_registration.dart';
|
||||
|
||||
class AuthBoolField extends AuthField {
|
||||
AuthBoolField({
|
||||
required super.name,
|
||||
required this.widgetType,
|
||||
super.title,
|
||||
super.validators = const [],
|
||||
super.value = '',
|
||||
this.leftWidget,
|
||||
this.rightWidget,
|
||||
this.onChange,
|
||||
});
|
||||
|
||||
final Widget? leftWidget;
|
||||
final Widget? rightWidget;
|
||||
final BoolWidgetType widgetType;
|
||||
final Function(String value)? onChange;
|
||||
|
||||
@override
|
||||
Widget build() {
|
||||
return FlutterFormInputBool(
|
||||
widgetType: widgetType,
|
||||
onChanged: (v) {
|
||||
value = v;
|
||||
onChange?.call(value);
|
||||
},
|
||||
validator: (value) {
|
||||
for (var validator in validators) {
|
||||
var output = validator(value);
|
||||
if (output != null) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
leftWidget: leftWidget,
|
||||
rightWidget: rightWidget,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,18 +4,18 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class AuthField {
|
||||
abstract class AuthField<T> {
|
||||
AuthField({
|
||||
required this.name,
|
||||
this.title,
|
||||
this.validators = const [],
|
||||
this.value = '',
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final String name;
|
||||
final Widget? title;
|
||||
List<String? Function(String?)> validators;
|
||||
String value;
|
||||
List<String? Function(T?)> validators;
|
||||
T value;
|
||||
|
||||
Widget build();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class RegistrationScreen extends StatelessWidget {
|
|||
final RegistrationOptions registrationOptions;
|
||||
|
||||
Future<void> register({
|
||||
required HashMap<String, String> values,
|
||||
required HashMap<String, dynamic> values,
|
||||
required void Function(int? pageToReturn) onError,
|
||||
}) async {
|
||||
try {
|
||||
|
|
|
@ -7,11 +7,19 @@ description: A Flutter Registration package
|
|||
version: 1.2.0
|
||||
repository: https://github.com/Iconica-Development/flutter_registration
|
||||
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.0 <3.0.0"
|
||||
flutter: ">=1.17.0"
|
||||
|
||||
dependencies:
|
||||
flutter_input_library:
|
||||
path: ../flutter_input_library
|
||||
# git:
|
||||
# url: https://github.com/Iconica-Development/flutter_input_library
|
||||
# ref: 2.7.0
|
||||
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_localizations:
|
||||
|
|
Loading…
Reference in a new issue