Skip to content

Commit 637de41

Browse files
committed
Merge branch 'drawing-pad' into access_fields_by_key
# Conflicts: # example/lib/main.dart
2 parents c3ebe72 + 3b9bbc5 commit 637de41

File tree

8 files changed

+363
-479
lines changed

8 files changed

+363
-479
lines changed

.idea/libraries/Dart_Packages.xml

Lines changed: 10 additions & 314 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Flutter_Plugins.xml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 216 additions & 144 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/main.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,17 @@ class MyHomePageState extends State<MyHomePage> {
310310
Expanded(
311311
child: FormBuilder(
312312
context,
313-
// key: _fbKey,
313+
key: _fbKey,
314314
autovalidate: autoValidate,
315315
readonly: readOnly,
316-
// showResetButton: true,
317-
// resetButtonContent: Text("Clear Form"),
316+
onChanged: (formValue) {
317+
print(formValue);
318+
},
318319
controls: [
319320
FormBuilderInput.typeAhead(
320321
label: 'Country',
321322
attribute: 'country',
322-
require: true,
323+
// require: true,
323324
itemBuilder: (context, country) {
324325
return ListTile(
325326
title: Text(country),
@@ -344,7 +345,7 @@ class MyHomePageState extends State<MyHomePage> {
344345
FormBuilderInput.chipsInput(
345346
label: 'Chips',
346347
attribute: 'chips_test',
347-
require: true,
348+
// require: true,
348349
value: [
349350
Contact('Andrew', '[email protected]',
350351
'https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX4057996.jpg'),
@@ -398,6 +399,8 @@ class MyHomePageState extends State<MyHomePage> {
398399
attribute: "name",
399400
label: "Name",
400401
value: "John Doe",
402+
// require: true,
403+
// readonly: true,
401404
require: true,
402405
// readonly: true,
403406
min: 3,
@@ -409,7 +412,7 @@ class MyHomePageState extends State<MyHomePage> {
409412
),
410413
FormBuilderInput.dropdown(
411414
attribute: "dropdown",
412-
require: true,
415+
// require: true,
413416
label: "Dropdown",
414417
hint: "Select Option",
415418
options: [
@@ -421,8 +424,8 @@ class MyHomePageState extends State<MyHomePage> {
421424
FormBuilderInput.number(
422425
attribute: "age",
423426
label: "Age",
424-
require: true,
425-
min: 18,
427+
// require: true,
428+
// min: 18,
426429
),
427430
FormBuilderInput.textField(
428431
type: FormBuilderInput.TYPE_MULTILINE_TEXT,
@@ -535,6 +538,12 @@ class MyHomePageState extends State<MyHomePage> {
535538
step: 1,
536539
hint: "Hint",
537540
),
541+
FormBuilderInput.signaturePad(
542+
label: "Signature",
543+
attribute: "signature",
544+
hint: "Hint",
545+
require: true,
546+
),
538547
FormBuilderInput.rate(
539548
label: "Rate",
540549
attribute: "rate",
@@ -553,16 +562,14 @@ class MyHomePageState extends State<MyHomePage> {
553562
.toList(),
554563
),
555564
],
556-
onChanged: (formValue) {
557-
print(formValue);
558-
},
559565
),
560566
),
561567
MaterialButton(
562568
child: Text('External submit'),
563569
onPressed: () {
564570
_fbKey.currentState.save();
565571
if (_fbKey.currentState.validate()) {
572+
print('validationSucceded');
566573
print(_fbKey.currentState.value);
567574
} else {
568575
print("External FormValidation failed");

lib/src/form_builder.dart

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import 'dart:typed_data';
2+
import 'dart:ui' as ui;
3+
14
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
25
import 'package:flutter/cupertino.dart';
36
import 'package:flutter/material.dart';
47
import 'package:flutter_chips_input/flutter_chips_input.dart';
8+
import 'package:flutter_form_builder/src/form_builder_input.dart';
59
import 'package:flutter_typeahead/flutter_typeahead.dart';
610
import 'package:intl/intl.dart';
11+
import 'package:signature/signature.dart';
712
import 'package:sy_flutter_widgets/sy_flutter_widgets.dart';
813

914
import './form_builder_input.dart';
@@ -193,8 +198,8 @@ class FormBuilderState extends State<FormBuilder> {
193198
val.isNotEmpty) {
194199
Pattern pattern =
195200
r"(https?|ftp)://([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:‌​,.;]*)?";
196-
if (!RegExp(pattern, caseSensitive: false)
197-
.hasMatch(val)) return '$val is not a valid URL';
201+
if (!RegExp(pattern, caseSensitive: false).hasMatch(val))
202+
return '$val is not a valid URL';
198203
}
199204

200205
if (formControl.validator != null)
@@ -317,8 +322,7 @@ class FormBuilderState extends State<FormBuilder> {
317322
return formControl.validator(val);
318323
},
319324
onSaved: (val) => value[formControl.attribute] = val,
320-
getImmediateSuggestions:
321-
formControl.getImmediateSuggestions,
325+
getImmediateSuggestions: formControl.getImmediateSuggestions,
322326
errorBuilder: formControl.errorBuilder,
323327
noItemsFoundBuilder: formControl.noItemsFoundBuilder,
324328
loadingBuilder: formControl.loadingBuilder,
@@ -851,6 +855,72 @@ class FormBuilderState extends State<FormBuilder> {
851855
),
852856
);
853857
break;
858+
859+
case FormBuilderInput.TYPE_SIGNATURE_PAD:
860+
var _signatureCanvas = Signature(
861+
points: formControl.points,
862+
width: formControl.width,
863+
height: formControl.height,
864+
backgroundColor: formControl.backgroundColor,
865+
penColor: formControl.penColor,
866+
penStrokeWidth: formControl.penStrokeWidth,
867+
);
868+
869+
return FormField<Image>(
870+
key: Key(formControl.attribute),
871+
enabled: !(widget.readonly || formControl.readonly),
872+
initialValue: formControl.value,
873+
onSaved: (val) async {
874+
Uint8List signature = await _signatureCanvas.exportBytes();
875+
var image = Image.memory(signature).image;
876+
print(image);
877+
value[formControl.attribute] = image;
878+
},
879+
validator: (value) {
880+
if (formControl.require && _signatureCanvas.isEmpty)
881+
return "${formControl.label} is required";
882+
if (formControl.validator != null)
883+
return formControl.validator(value);
884+
},
885+
builder: (FormFieldState<dynamic> field) {
886+
887+
return InputDecorator(
888+
decoration: InputDecoration(
889+
// icon: const Icon(Icons.person),
890+
enabled: !(widget.readonly || formControl.readonly),
891+
hintText: formControl.hint,
892+
labelText: formControl.label,
893+
errorText: field.errorText,
894+
),
895+
child: Column(
896+
children: <Widget>[
897+
Container(
898+
decoration: BoxDecoration(
899+
border: Border.all(color: Colors.grey),
900+
),
901+
child: GestureDetector(
902+
onVerticalDragUpdate: (_) {},
903+
child: _signatureCanvas,
904+
),
905+
),
906+
Row(
907+
children: <Widget>[
908+
Expanded(child: SizedBox()),
909+
FlatButton(
910+
onPressed: () {
911+
_signatureCanvas.clear();
912+
field.didChange(null);
913+
},
914+
child: Text('Clear')),
915+
],
916+
),
917+
],
918+
),
919+
);
920+
},
921+
);
922+
923+
break;
854924
}
855925
}).toList(),
856926
),

lib/src/form_builder_input.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'dart:ui';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_chips_input/flutter_chips_input.dart';
35
import 'package:flutter_typeahead/flutter_typeahead.dart';
6+
import 'package:signature/signature.dart';
47

58
import './form_builder_input_option.dart';
69

@@ -31,6 +34,7 @@ class FormBuilderInput {
3134
static const String TYPE_RATE = "Rate";
3235
static const String TYPE_SEGMENTED_CONTROL = "SegmentedControl";
3336
static const String TYPE_CHIPS_INPUT = "ChipsInput";
37+
static const String TYPE_SIGNATURE_PAD = "DrawingPad";
3438

3539
String label;
3640
String attribute;
@@ -42,6 +46,12 @@ class FormBuilderInput {
4246
dynamic min;
4347
dynamic max;
4448
int divisions;
49+
Color penColor;
50+
Color backgroundColor;
51+
double penStrokeWidth;
52+
double height;
53+
double width;
54+
List<Point> points;
4555
num step;
4656
String format;
4757
IconData icon;
@@ -138,6 +148,24 @@ class FormBuilderInput {
138148
type = FormBuilderInput.TYPE_TYPE_AHEAD;
139149
}
140150

151+
FormBuilderInput.signaturePad({
152+
@required this.label,
153+
@required this.attribute,
154+
this.readonly = false,
155+
this.penColor = Colors.black,
156+
this.penStrokeWidth = 3,
157+
this.width,
158+
this.points,
159+
this.height = 250,
160+
this.backgroundColor = Colors.white70,
161+
this.hint,
162+
this.value,
163+
this.require = false,
164+
this.validator,
165+
}) {
166+
type = FormBuilderInput.TYPE_SIGNATURE_PAD;
167+
}
168+
141169
FormBuilderInput.number({
142170
@required this.label,
143171
@required this.attribute,

pubspec.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ packages:
4848
url: "https://pub.dartlang.org"
4949
source: hosted
5050
version: "1.1.0"
51+
flutter_signature_pad:
52+
dependency: "direct main"
53+
description:
54+
name: flutter_signature_pad
55+
url: "https://pub.dartlang.org"
56+
source: hosted
57+
version: "1.0.0"
5158
flutter_test:
5259
dependency: "direct dev"
5360
description: flutter
@@ -109,6 +116,13 @@ packages:
109116
url: "https://pub.dartlang.org"
110117
source: hosted
111118
version: "2.0.1"
119+
signature:
120+
dependency: "direct main"
121+
description:
122+
name: signature
123+
url: "https://pub.dartlang.org"
124+
source: hosted
125+
version: "2.0.0"
112126
sky_engine:
113127
dependency: transitive
114128
description: flutter
@@ -179,4 +193,4 @@ packages:
179193
version: "2.0.8"
180194
sdks:
181195
dart: ">=2.1.0 <3.0.0"
182-
flutter: ">=0.1.4 <2.0.0"
196+
flutter: ">=0.6.0 <2.0.0"

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_form_builder
22
description: Package to build Material Form with components such as TextField (With number, url, email validation), DropDown, TypeAhead, Radios, Checkboxes
3-
version: 1.5.1
3+
version: 1.4.0
44
author: Danvick Miller <[email protected]>
55
homepage: https://github.com/danvick/flutter_form_builder
66

@@ -16,6 +16,7 @@ dependencies:
1616
sy_flutter_widgets: ^0.1.4
1717
flutter_chips_input: ^1.1.0
1818
datetime_picker_formfield: ^0.1.8
19+
signature: ^2.0.0
1920

2021
dev_dependencies:
2122
flutter_test:

0 commit comments

Comments
 (0)