Skip to content
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
54 changes: 18 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ This package provides a set of pre-built `FormField` widgets that integrate seam
- Date, Time, Duration
- Single Item Picker
- Multiple Item Picker
- Bool value
- Switch (Boolean)
- Radio Button
- CheckBox Group

Expand Down Expand Up @@ -154,17 +154,15 @@ Example Simple Text
),
```

Example Password Text
### FlPasswordFormField

``` dart
FlTextFormField(
```dart
FlPasswordFormField(
prefixIcon: const Icon(Icons.lock),
label: 'Password',
placeholderText: '* * * * * *',
isRequired: true,
isPassword: true,
),

```

Example Area Text
Expand All @@ -181,6 +179,16 @@ Example Area Text
),
```

### FlMoneyFormField

```dart
FlMoneyFormField(
label: 'Amount',
currency: 'USD',
initialValue: 1000.00,
),
```

### FlDateFormField

<img src="https://raw.githubusercontent.com/dangngocduc/fl_form/master/images/date_form_field_guide.png" width="100%"/>
Expand Down Expand Up @@ -308,44 +316,18 @@ Example Area Text
),
```

### FlBoolFormField
### FlSwitchFormField

<img src="https://raw.githubusercontent.com/dangngocduc/fl_form/master/images/bool_form_field.png" width="50%"/>

#### Default Bool FormField
#### Default Switch FormField

```flutter
FlBoolFormField(
spacing: 16,
title: 'Select All',
FlSwitchFormField(
label: 'Select All',
)
```

#### Custom Bool FormField

```flutter
FlRawBoolFormField(
title: 'Select All',
rawBuilder: (context, data, didChange) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(
children: [
Checkbox(
value: data ?? false,
onChanged: (value) {
didChange(value);
},
),
const Expanded(
child: Text('Select All'),
)
],
),
);
},
),
```

### FlSingleItemPickerFormField

Expand Down
45 changes: 21 additions & 24 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import 'package:example/main_example.dart';
import 'package:flutter/material.dart';

import 'package:fl_form/formfield/fl_form_field_theme.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
ThemeMode _themeMode = ThemeMode.dark;

void _toggleTheme() {
setState(() {
_themeMode = _themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
});
}

@override
Widget build(BuildContext context) {
return Center(
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
size: Size(
MediaQuery.of(context).size.width / 2,
MediaQuery.of(context).size.height,
),
),
child: Builder(
builder: (context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.dark(
useMaterial3: true,
).copyWith(extensions: [
FlFormFieldTheme.dark(context),
]),
home: const MainExample(),
);
},
)),
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.light(useMaterial3: true).copyWith(extensions: [FlFormFieldTheme.light(context)]),
darkTheme: ThemeData.dark(useMaterial3: true).copyWith(extensions: [FlFormFieldTheme.dark(context)]),
themeMode: _themeMode,
home: MainExample(onToggleTheme: _toggleTheme),
);
}
}
40 changes: 37 additions & 3 deletions example/lib/main_example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:example/page_demo/all_form_fields_page.dart';
import 'package:example/page_demo/avatar_form_field_page.dart';
import 'package:example/page_demo/bool_form_field_page.dart';
import 'package:example/page_demo/date_form_field_page.dart';
Expand All @@ -13,18 +14,51 @@ import 'page_demo/item_picker_page.dart';
import 'page_demo/multiple_item_picker_page.dart';

class MainExample extends StatelessWidget {
const MainExample({Key? key}) : super(key: key);
final VoidCallback onToggleTheme;

const MainExample({Key? key, required this.onToggleTheme}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
appBar: AppBar(
centerTitle: true,
title: const Text('Example'),
actions: [
IconButton(
icon: const Icon(Icons.brightness_6),
onPressed: onToggleTheme,
),
],
),
body: ListView(
body: ListView(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Card(
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return AllFormFieldsPage(onToggleTheme: onToggleTheme);
},
));
},
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 16, horizontal: 16),
child: Row(
children: [
Expanded(
child: Text('All Form Fields'),
),
Icon(Icons.keyboard_arrow_right_outlined)
],
),
),
),
),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Card(
Expand Down
120 changes: 120 additions & 0 deletions example/lib/page_demo/all_form_fields_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import 'package:fl_form/fl_form.dart';
import 'package:fl_form/formfield/fl_double_form_field.dart';
import 'package:fl_form/formfield/fl_int_form_field.dart';
import 'package:flutter/material.dart';

class SimpleData {
final String title;
final String subTitle;

SimpleData({required this.title, required this.subTitle});

@override
String toString() {
return title;
}
}

class AllFormFieldsPage extends StatelessWidget {
final VoidCallback onToggleTheme;

const AllFormFieldsPage({Key? key, required this.onToggleTheme}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('All Form Fields'),
actions: [IconButton(icon: const Icon(Icons.brightness_6), onPressed: onToggleTheme)],
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FlTextFormField(label: 'Email', placeholderText: 'Type your email'),
const SizedBox(height: 24),
FlPasswordFormField(label: 'Password', placeholderText: 'Enter your password'),
const SizedBox(height: 24),
FlMoneyFormField(label: 'Amount', currency: 'USD'),
const SizedBox(height: 24),
FlDateFormField(label: 'Date of Birth', placeholderText: 'dd/MM/yyyy'),
const SizedBox(height: 24),
FlSwitchFormField(label: 'Accept Terms & Conditions'),
const SizedBox(height: 24),
FlAvatarFormField(label: 'Profile Picture'),
const SizedBox(height: 24),
FlIntFormField(label: 'Integer', placeholderText: 'Enter an integer'),
const SizedBox(height: 24),
FlDoubleFormField(label: 'Double', placeholderText: 'Enter a double'),
const SizedBox(height: 24),
FlTimeFormField(label: 'Time', placeholderText: 'HH:MM'),
const SizedBox(height: 24),
FlDateAndTimeFormField(label: 'Date and Time', placeholderText: 'dd/MM/yyyy HH:mm'),
const SizedBox(height: 24),
FlDurationFormField(label: 'Duration', placeholderText: 'hh:mm'),
const SizedBox(height: 24),
FlRadioButtonFormField(
label: 'Radio Buttons',
options: [
FormFieldOption(value: 'Option 1'),
FormFieldOption(value: 'Option 2'),
FormFieldOption(value: 'Option 3'),
],
),
const SizedBox(height: 24),
FlCheckboxGroupFormField(
label: 'Checkbox Group',
options: [
FormFieldOption(value: 'Option 1'),
FormFieldOption(value: 'Option 2'),
FormFieldOption(value: 'Option 3'),
],
),
const SizedBox(height: 24),
FlSegmentedButtonFormField<String>(
label: 'Segmented Button',
options: const [
FormFieldOption(value: 'one', label: 'One'),
FormFieldOption(value: 'two', label: 'Two'),
FormFieldOption(value: 'three', label: 'Three'),
],
),
const SizedBox(height: 24),
SingleItemPickerFormField(
label: 'Single Item Picker',
options: [
FormFieldOption(value: 'Title 1'),
FormFieldOption(value: 'Title 2'),
],
),
const SizedBox(height: 24),
MultipleItemPickerFormField(
label: 'Multiple Item Picker',
options: [
FormFieldOption(value: 'Title 1'),
FormFieldOption(value: 'Title 2'),
],
),
const SizedBox(height: 24),
FlSearchItemFormField(
label: 'Search Item Picker',
onSearch: (query) async {
await Future.delayed(const Duration(seconds: 1));
return ['Result 1', 'Result 2'];
},
),
const SizedBox(height: 24),
FlMultipleSearchItemFormField(
label: 'Multiple Search Item Picker',
onSearch: (query) async {
await Future.delayed(const Duration(seconds: 1));
return ['Result 1', 'Result 2'];
},
),
],
),
),
);
}
}
Loading