Skip to content

Commit

Permalink
Add samples for form textfield
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 30, 2024
1 parent 10b46fa commit 660b0c3
Show file tree
Hide file tree
Showing 58 changed files with 213 additions and 175 deletions.
4 changes: 0 additions & 4 deletions forui/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
targets:
$default:
builders:
stevia_runner:steviaAssetGenerator:
generate_for:
- assets/**

mockito:mockBuilder:
generate_for:
- test/**.dart
75 changes: 31 additions & 44 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,43 @@ class ExampleWidget extends StatefulWidget {
}

class _ExampleWidgetState extends State<ExampleWidget> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
Expanded(
child: FTabs(
tabs: [
FTabEntry(
label: 'Account',
content: FCard(
title: 'Account',
subtitle: 'Make changes to your account here. Click save when you are done.',
child: Column(
children: [
Container(
color: Colors.red,
height: 100,
),
],
),
),
),
FTabEntry(
label: 'Password',
content: FCard(
title: 'Password',
subtitle: 'Change your password here. After saving, you will be logged out.',
child: Column(
children: [
Container(
color: Colors.blue,
height: 100,
)
],
),
),
),
],
),
padding: const EdgeInsets.all(8.0),
child: Form(
key: _formKey,
child: Column(
children: [
FTextField.email(
label: const Text('Email'),
hint: '[email protected]',
help: const Text(''),
validator: (value) => (value?.contains('@') ?? false) ? null : 'Please enter a valid email.',
),
const SizedBox(height: 4),
FTextField.password(
label: const Text('Password'),
hint: '',
help: const Text(''),
validator: (value) => (value?.length ?? 0) >= 8 ? null : 'Password must be at least 8 characters long.',
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 30),
child: FButton(
rawLabel: const Text('Login'),
onPress: () => _formKey.currentState!.validate(),
),
],
),
);
)
],
),
)
);
}
60 changes: 4 additions & 56 deletions forui/lib/src/widgets/text_field/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ final class FTextField extends StatelessWidget {
/// Whitespace characters (e.g. newline, space, tab) are included in the character count.
///
/// If [maxLengthEnforcement] is [MaxLengthEnforcement.none], then more than [maxLength] characters may be entered,
/// but the error counter and divider will switch to the [style]'s [FTextFieldStyle.error] when the limit is exceeded.
/// but the error counter and divider will switch to the [style]'s [FTextFieldStyle.errorStyle] when the limit is exceeded.
final int? maxLength;

/// Determines how the [maxLength] limit should be enforced.
Expand Down Expand Up @@ -731,9 +731,9 @@ final class FTextField extends StatelessWidget {
final theme = context.theme;
final style = this.style ?? theme.textFieldStyle;
final stateStyle = switch (this) {
_ when !enabled => style.disabled,
_ when error != null => style.error,
_ => style.enabled,
_ when !enabled => style.disabledStyle,
_ when error != null => style.errorStyle,
_ => style.enabledStyle,
};

final textFormField = MergeSemantics(
Expand Down Expand Up @@ -765,7 +765,6 @@ final class FTextField extends StatelessWidget {
),
child: _Field(
parent: this,
initialDecoration: _decoration(style, stateStyle),
style: style,
stateStyle: stateStyle,
key: key,
Expand All @@ -790,57 +789,6 @@ final class FTextField extends StatelessWidget {
: textFormField;
}

InputDecoration _decoration(
FTextFieldStyle style,
FTextFieldStateStyle current,
) => InputDecoration(
suffixIcon: suffix,
// See https://stackoverflow.com/questions/70771410/flutter-how-can-i-remove-the-content-padding-for-error-in-textformfield
prefix: Padding(padding: EdgeInsets.only(left: style.contentPadding.left)),
contentPadding: style.contentPadding.copyWith(left: 0),
hintText: hint,
hintStyle: current.hintTextStyle,
helper: help == null ? null : DefaultTextStyle.merge(style: current.footerTextStyle, child: help!),
helperStyle: current.footerTextStyle,
error: error == null ? null : DefaultTextStyle.merge(style: current.footerTextStyle, child: error!),
errorStyle: current.footerTextStyle,
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: style.disabled.unfocused.color,
width: style.disabled.unfocused.width,
),
borderRadius: style.disabled.unfocused.radius,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: style.enabled.unfocused.color,
width: style.enabled.unfocused.width,
),
borderRadius: style.enabled.unfocused.radius,
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: style.enabled.focused.color,
width: style.enabled.focused.width,
),
borderRadius: current.focused.radius,
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: style.error.unfocused.color,
width: style.error.unfocused.width,
),
borderRadius: style.error.unfocused.radius,
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: style.error.focused.color,
width: style.error.focused.width,
),
borderRadius: style.error.focused.radius,
),
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down
Loading

0 comments on commit 660b0c3

Please sign in to comment.