mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 19:03:47 +02:00
add input date picker
This commit is contained in:
parent
9c76d2766a
commit
a83b32bf52
12 changed files with 214 additions and 7 deletions
|
@ -1,9 +1,10 @@
|
||||||
## 0.0.1 - September 29th 2022
|
## 0.0.2 - October 10th 2022
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
|
||||||
## 0.0.2 - October 12th 2022
|
## 0.0.2 - October 12th 2022
|
||||||
|
|
||||||
- Added a multi line plain text input widget
|
- Added a multi line plain text input widget
|
||||||
|
- Added date input widget
|
||||||
- Ability to set the scrolldirection of the pageview
|
- Ability to set the scrolldirection of the pageview
|
||||||
- Ability to set the scrollphysics of the pages' scrollview.
|
- Ability to set the scrollphysics of the pages' scrollview.
|
||||||
|
|
|
@ -25,7 +25,7 @@ class _AgePageState extends State<AgePage> {
|
||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
title: "What is your age?",
|
title: "What is your age?",
|
||||||
pageNumber: 1,
|
pageNumber: 1,
|
||||||
amountOfPages: 3,
|
amountOfPages: 4,
|
||||||
flutterFormWidgets: [
|
flutterFormWidgets: [
|
||||||
FlutterFormInputNumberPicker(
|
FlutterFormInputNumberPicker(
|
||||||
minValue: 12,
|
minValue: 12,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class _CarouselPageState extends State<CarouselPage> {
|
||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
title: "What's your favorite car?",
|
title: "What's your favorite car?",
|
||||||
pageNumber: 3,
|
pageNumber: 3,
|
||||||
amountOfPages: 3,
|
amountOfPages: 4,
|
||||||
flutterFormWidgets: [
|
flutterFormWidgets: [
|
||||||
FlutterFormInputCarousel(
|
FlutterFormInputCarousel(
|
||||||
controller: widget.inputController, items: getCars())
|
controller: widget.inputController, items: getCars())
|
||||||
|
|
42
example/lib/example_pages/date_page.dart
Normal file
42
example/lib/example_pages/date_page.dart
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_form/flutter_form.dart';
|
||||||
|
import 'package:form_example/template_page.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
class DatePage extends StatefulWidget {
|
||||||
|
const DatePage({
|
||||||
|
required this.dateController,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final FlutterFormInputPlainTextController dateController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DatePage> createState() => _DatePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DatePageState extends State<DatePage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var size = MediaQuery.of(context).size;
|
||||||
|
var fontSize = size.height / 40;
|
||||||
|
|
||||||
|
return TemplatePage(
|
||||||
|
size: size,
|
||||||
|
fontSize: fontSize,
|
||||||
|
pageNumber: 4,
|
||||||
|
amountOfPages: 4,
|
||||||
|
title: "Please enter a date",
|
||||||
|
flutterFormWidgets: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(40, 0, 40, 40),
|
||||||
|
child: FlutterFormInputDate(
|
||||||
|
dateFormat: DateFormat.yMd(),
|
||||||
|
label: const Text("Date"),
|
||||||
|
controller: widget.dateController,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ class _NamePageState extends State<NamePage> {
|
||||||
size: size,
|
size: size,
|
||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
pageNumber: 2,
|
pageNumber: 2,
|
||||||
amountOfPages: 3,
|
amountOfPages: 4,
|
||||||
title: "Please enter your name",
|
title: "Please enter your name",
|
||||||
flutterFormWidgets: [
|
flutterFormWidgets: [
|
||||||
Padding(
|
Padding(
|
||||||
|
|
|
@ -6,6 +6,8 @@ import 'package:form_example/example_pages/carousel_page.dart';
|
||||||
import 'package:form_example/example_pages/check_page.dart';
|
import 'package:form_example/example_pages/check_page.dart';
|
||||||
import 'package:form_example/example_pages/name_page.dart';
|
import 'package:form_example/example_pages/name_page.dart';
|
||||||
|
|
||||||
|
import 'example_pages/date_page.dart';
|
||||||
|
|
||||||
class FormExample extends ConsumerStatefulWidget {
|
class FormExample extends ConsumerStatefulWidget {
|
||||||
const FormExample({Key? key}) : super(key: key);
|
const FormExample({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -60,6 +62,15 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
FlutterFormInputPlainTextController dateController =
|
||||||
|
FlutterFormInputPlainTextController(
|
||||||
|
mandatory: true,
|
||||||
|
id: "date",
|
||||||
|
checkPageTitle: (dynamic date) {
|
||||||
|
return "Date: $date";
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
@ -189,6 +200,11 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
||||||
cars: cars,
|
cars: cars,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
FlutterFormPage(
|
||||||
|
child: DatePage(
|
||||||
|
dateController: dateController,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
checkPage: CheckPageExample()
|
checkPage: CheckPageExample()
|
||||||
.showCheckpage(context, size, fontSize, checkPageText),
|
.showCheckpage(context, size, fontSize, checkPageText),
|
||||||
|
|
|
@ -94,7 +94,7 @@ packages:
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
intl:
|
intl:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: intl
|
name: intl
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
|
|
@ -16,6 +16,7 @@ dependencies:
|
||||||
flutter_riverpod: ^1.0.4
|
flutter_riverpod: ^1.0.4
|
||||||
flutter_form:
|
flutter_form:
|
||||||
path: ../
|
path: ../
|
||||||
|
intl: ^0.17.0
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_form/utils/translation_service.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import '../../../../../flutter_form.dart';
|
||||||
|
|
||||||
|
/// Generates a [TextFormField] for passwords. It requires a [FlutterFormInputController]
|
||||||
|
/// as the [controller] parameter and an optional [Widget] as [label]
|
||||||
|
class DateInputField extends ConsumerStatefulWidget {
|
||||||
|
const DateInputField(
|
||||||
|
{Key? key,
|
||||||
|
required this.controller,
|
||||||
|
this.label,
|
||||||
|
this.showIcon = true,
|
||||||
|
this.icon = Icons.calendar_today,
|
||||||
|
required this.dateFormat})
|
||||||
|
: super(
|
||||||
|
key: key,
|
||||||
|
);
|
||||||
|
final FlutterFormInputController controller;
|
||||||
|
final DateFormat dateFormat;
|
||||||
|
final bool showIcon;
|
||||||
|
final IconData icon;
|
||||||
|
final Widget? label;
|
||||||
|
@override
|
||||||
|
ConsumerState<DateInputField> createState() => _DateInputFieldState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DateInputFieldState extends ConsumerState<DateInputField> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
String Function(String, {List<String>? params}) _ =
|
||||||
|
getTranslator(context, ref);
|
||||||
|
|
||||||
|
return TextFormField(
|
||||||
|
key: Key(widget.controller.value.toString()),
|
||||||
|
initialValue: widget.controller.value,
|
||||||
|
onSaved: (value) {
|
||||||
|
widget.controller.onSaved(value);
|
||||||
|
},
|
||||||
|
onTap: () async {
|
||||||
|
DateTime? pickedDate = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: DateTime.now(),
|
||||||
|
firstDate: DateTime.now(),
|
||||||
|
lastDate: DateTime.now().add(
|
||||||
|
const Duration(days: 2000),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (pickedDate != null) {
|
||||||
|
widget.controller.value = widget.dateFormat.format(pickedDate);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validator: (value) => widget.controller.onValidate(value, _),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: widget.showIcon ? Icon(widget.icon) : null,
|
||||||
|
focusColor: Theme.of(context).primaryColor,
|
||||||
|
label: widget.label ?? const Text("Date"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_form/src/widgets/input/input_types/input_date_picker/date_picker.dart';
|
||||||
|
import 'package:flutter_form/utils/translation_service.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import '../../../../../flutter_form.dart';
|
||||||
|
|
||||||
|
/// Input for a date used in a [FlutterForm].
|
||||||
|
///
|
||||||
|
/// Standard controller is [FlutterFormInputDateController].
|
||||||
|
class FlutterFormInputDate extends FlutterFormInputWidget {
|
||||||
|
const FlutterFormInputDate(
|
||||||
|
{Key? key,
|
||||||
|
required FlutterFormInputController controller,
|
||||||
|
Widget? label,
|
||||||
|
this.showIcon = true,
|
||||||
|
this.icon = Icons.calendar_today,
|
||||||
|
required this.dateFormat})
|
||||||
|
: super(
|
||||||
|
key: key,
|
||||||
|
controller: controller,
|
||||||
|
label: label,
|
||||||
|
);
|
||||||
|
final DateFormat dateFormat;
|
||||||
|
final bool showIcon;
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
String Function(String, {List<String>? params}) _ =
|
||||||
|
getTranslator(context, ref);
|
||||||
|
super.registerController(context);
|
||||||
|
|
||||||
|
return DateInputField(controller: controller, dateFormat: dateFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Controller for dates used by a [FlutterFormInputWidget] used in a [FlutterForm].
|
||||||
|
///
|
||||||
|
/// Mainly used by [FlutterFormInputDate].
|
||||||
|
class FlutterFormInputDateController
|
||||||
|
implements FlutterFormInputController<String> {
|
||||||
|
FlutterFormInputDateController({
|
||||||
|
required this.id,
|
||||||
|
this.mandatory = true,
|
||||||
|
this.value,
|
||||||
|
this.checkPageTitle,
|
||||||
|
this.checkPageDescription,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool mandatory;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String Function(String value)? checkPageTitle;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String Function(String value)? checkPageDescription;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onSaved(dynamic value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? onValidate(String? value,
|
||||||
|
String Function(String, {List<String>? params}) translator) {
|
||||||
|
if (mandatory) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return translator('shell.form.error.empty');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,3 +4,4 @@ export 'input_number_picker/input_number_picker.dart';
|
||||||
export 'input_password/input_password.dart';
|
export 'input_password/input_password.dart';
|
||||||
export 'input_plain_text.dart';
|
export 'input_plain_text.dart';
|
||||||
export 'input_slider/input_slider.dart';
|
export 'input_slider/input_slider.dart';
|
||||||
|
export 'input_date_picker/input_date_picker.dart';
|
||||||
|
|
|
@ -6,7 +6,7 @@ homepage:
|
||||||
publish_to: none
|
publish_to: none
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.18.0 <3.0.0'
|
sdk: ">=2.18.0 <3.0.0"
|
||||||
flutter: ">=1.17.0"
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -15,8 +15,8 @@ dependencies:
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_riverpod: ^1.0.4
|
flutter_riverpod: ^1.0.4
|
||||||
|
intl: ^0.17.0
|
||||||
localization: ^2.1.0
|
localization: ^2.1.0
|
||||||
|
|
||||||
sliding_up_panel: ^2.0.0+1
|
sliding_up_panel: ^2.0.0+1
|
||||||
uuid: ^3.0.6
|
uuid: ^3.0.6
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue