diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 0b8846d..64b4f9f 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -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" diff --git a/example/lib/main.dart b/example/lib/main.dart index 8abedd9..7c0748b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,10 +52,14 @@ class _MyHomePageState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ 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(() { @@ -69,32 +73,32 @@ class _MyHomePageState extends State { }, 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', diff --git a/example/pubspec.lock b/example/pubspec.lock index 080fbc7..7e1e0ff 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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" diff --git a/lib/dropdown_formfield.dart b/lib/dropdown_formfield.dart index d3df4f4..23fe0ac 100644 --- a/lib/dropdown_formfield.dart +++ b/lib/dropdown_formfield.dart @@ -5,77 +5,113 @@ import 'package:flutter/material.dart'; class DropDownFormField extends FormField { 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 onSaved, - FormFieldValidator 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? onSaved, + FormFieldValidator? 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 state) { - return Container( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - 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: [ + 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( - isExpanded: true, - hint: Text( - hintText, - style: TextStyle(color: Colors.grey.shade500), + Container( + child: DropdownButtonHideUnderline( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: DropdownButton( + 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( + 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( - 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), + ), + ], + ), ), ); }, diff --git a/pubspec.lock b/pubspec.lock index 03307d6..5be8e9b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 9c740a2..b8aa4e8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/cetorres/dropdown_formfield environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.15.0 <3.0.0" dependencies: flutter: