Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text alignment and design improvements #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/cetorres/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/cetorres/Projects/dropdown_formfield/example"
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\tahateber\Desktop\Flutter_drop_downmenu\dropdown_formfield\example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=/Users/cetorres/Projects/dropdown_formfield/example/lib/main.dart"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=/Users/cetorres/Projects/dropdown_formfield/example/.dart_tool/package_config.json"
export "PACKAGE_CONFIG=.packages"
36 changes: 20 additions & 16 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment.centerRight,
padding: EdgeInsets.all(16),
child: DropDownFormField(
titleText: 'My workout',
hintText: 'Please choose one',
backgroundColor: Colors.grey.shade200,
titleBackgroundColor: Colors.grey.shade300,
textAlign: Alignment.centerLeft,
titleText: 'Choose model',
hintText: 'Pick one',
value: _myActivity,
onSaved: (value) {
setState(() {
Expand All @@ -69,32 +73,32 @@ class _MyHomePageState extends State<MyHomePage> {
},
dataSource: [
{
"display": "Running",
"value": "Running",
"display": "one",
"value": "1",
},
{
"display": "Climbing",
"value": "Climbing",
"display": "two",
"value": "2",
},
{
"display": "Walking",
"value": "Walking",
"display": "three",
"value": "3",
},
{
"display": "Swimming",
"value": "Swimming",
"display": "four",
"value": "4",
},
{
"display": "Soccer Practice",
"value": "Soccer Practice",
"display": "five",
"value": "5",
},
{
"display": "Baseball Practice",
"value": "Baseball Practice",
"display": "six",
"value": "6",
},
{
"display": "Football Practice",
"value": "Football Practice",
"display": "seven",
"value": "7",
},
],
textField: 'display',
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ packages:
source: hosted
version: "2.1.1"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.15.0 <3.0.0"
150 changes: 93 additions & 57 deletions lib/dropdown_formfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,113 @@ import 'package:flutter/material.dart';
class DropDownFormField extends FormField<dynamic> {
final String titleText;
final String hintText;
final AlignmentGeometry textAlign;
final Color backgroundColor;
final Color titleBackgroundColor;
final bool required;
final String errorText;
final dynamic value;
final List dataSource;
final String textField;
final String valueField;
final Function onChanged;
final List? dataSource;
final String? textField;
final String? valueField;
final Function? onChanged;
final bool filled;
final EdgeInsets contentPadding;

DropDownFormField(
{FormFieldSetter<dynamic> onSaved,
FormFieldValidator<dynamic> validator,
AutovalidateMode autovalidate = AutovalidateMode.disabled,
this.titleText = 'Title',
this.hintText = 'Select one option',
this.required = false,
this.errorText = 'Please select one option',
this.value,
this.dataSource,
this.textField,
this.valueField,
this.onChanged,
this.filled = true,
this.contentPadding = const EdgeInsets.fromLTRB(12, 12, 8, 0)})
: super(
DropDownFormField({
FormFieldSetter<dynamic>? onSaved,
FormFieldValidator<dynamic>? validator,
AutovalidateMode autovalidate = AutovalidateMode.disabled,
this.titleText = 'Title',
this.hintText = 'Select one option',
this.textAlign = Alignment.centerLeft,
this.backgroundColor = Colors.white70,
this.titleBackgroundColor = Colors.white70,
this.required = false,
this.errorText = 'Please select one option',
this.value,
this.dataSource,
this.textField,
this.valueField,
this.onChanged,
this.filled = true,
}) : super(
onSaved: onSaved,
validator: validator,
autovalidateMode: autovalidate,
initialValue: value == '' ? null : value,
builder: (FormFieldState<dynamic> state) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InputDecorator(
decoration: InputDecoration(
contentPadding: contentPadding,
labelText: titleText,
filled: filled,
return ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Container(
color: backgroundColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15.0),
topRight: Radius.circular(15.0),
),
child: Container(
color: titleBackgroundColor,
width: double.infinity,
alignment: textAlign,
child: Padding(
padding:
const EdgeInsets.fromLTRB(15.0, 8.0, 15.0, 8.0),
child: Text(
titleText,
style: TextStyle(color: Colors.grey.shade700),
),
),
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<dynamic>(
isExpanded: true,
hint: Text(
hintText,
style: TextStyle(color: Colors.grey.shade500),
Container(
child: DropdownButtonHideUnderline(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButton<dynamic>(
isExpanded: true,
hint: Container(
alignment: textAlign,
child: Text(
hintText,
style: TextStyle(color: Colors.grey.shade500),
),
),
value: value == '' ? null : value,
onChanged: (dynamic newValue) {
state.didChange(newValue);
onChanged!(newValue);
},
items: dataSource!.map((item) {
return DropdownMenuItem<dynamic>(
value: item[valueField],
child: Container(
alignment: textAlign,
child: Padding(
padding: const EdgeInsets.fromLTRB(
15.0, 8.0, 0, 8.0),
child: Text(item[textField],
textDirection: TextDirection.rtl,
overflow: TextOverflow.ellipsis),
),
),
);
}).toList(),
),
),
value: value == '' ? null : value,
onChanged: (dynamic newValue) {
state.didChange(newValue);
onChanged(newValue);
},
items: dataSource.map((item) {
return DropdownMenuItem<dynamic>(
value: item[valueField],
child: Text(item[textField],
overflow: TextOverflow.ellipsis),
);
}).toList(),
),
),
),
SizedBox(height: state.hasError ? 5.0 : 0.0),
Text(
state.hasError ? state.errorText : '',
style: TextStyle(
color: Colors.redAccent.shade700,
fontSize: state.hasError ? 12.0 : 0.0),
),
],
SizedBox(height: state.hasError ? 5.0 : 0.0),
Text(
'',
style: TextStyle(
color: Colors.redAccent.shade700,
fontSize: state.hasError ? 12.0 : 0.0),
),
],
),
),
);
},
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ packages:
source: hosted
version: "2.1.1"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.15.0 <3.0.0"
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: dropdown_formfield
description: A dropdown form field using a dropdown button inside a form field.
version: 0.1.4
author: Carlos E. Torres <[email protected]>
homepage: https://github.com/cetorres/dropdown_formfield

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.15.0 <3.0.0"

dependencies:
flutter:
Expand Down