Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
koji-1009 committed May 13, 2023
1 parent 2dbeb06 commit 61271eb
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 13 deletions.
108 changes: 107 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,110 @@ PasswordTextField is a TextField that manages the toggle of obscure.

## How to use

Replace your `TextField`(`PasswordTextField`) or `TextFormField`(`PasswordTextFormField`).
### `TextField`(`PasswordTextField`)

```dart
class PasswordWidget extends StatelessWidget {
const PasswordWidget({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
'TextField',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(
height: 8,
),
const PasswordTextField(
decoration: InputDecoration(
border: UnderlineInputBorder(),
hintText: 'underline',
),
),
const SizedBox(
height: 16,
),
const PasswordTextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'outline',
),
),
],
);
}
}
```

### `TextFormField`(`PasswordTextFormField`)

```dart
class PasswordFormWidget extends StatefulWidget {
const PasswordFormWidget({super.key});
@override
State<PasswordFormWidget> createState() => _PasswordFormWidgetState();
}
class _PasswordFormWidgetState extends State<PasswordFormWidget> {
final _formState = GlobalKey<FormState>();
final _textFormFieldController = TextEditingController();
@override
void dispose() {
_textFormFieldController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Form(
key: _formState,
child: Column(
children: [
Text(
'TextFormField',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(
height: 8,
),
PasswordTextFormField(
controller: _textFormFieldController,
validator: (value) {
if ((value?.length ?? 0) < 6) {
return 'Password must be at least 6 characters';
}
return null;
},
),
const SizedBox(
height: 16,
),
OutlinedButton(
onPressed: () {
final state = _formState.currentState;
if (state == null || !state.validate()) {
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Password ${_textFormFieldController.text} is valid!',
),
),
);
},
child: const Text('Check'),
),
],
),
);
}
}
```
28 changes: 16 additions & 12 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ class MyApp extends StatelessWidget {
title: 'password_text_field demo',
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blue,
brightness: Brightness.light,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.light,
),
),
darkTheme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blue,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.dark,
),
),
home: const MyHomePage(),
);
Expand All @@ -50,20 +54,20 @@ class MyHomePage extends StatelessWidget {
),
child: const Column(
children: [
_PasswordWidget(),
PasswordWidget(),
SizedBox(
height: 32,
),
_PasswordFormWidget(),
PasswordFormWidget(),
],
),
),
);
}
}

class _PasswordWidget extends StatelessWidget {
const _PasswordWidget();
class PasswordWidget extends StatelessWidget {
const PasswordWidget({super.key});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -96,14 +100,14 @@ class _PasswordWidget extends StatelessWidget {
}
}

class _PasswordFormWidget extends StatefulWidget {
const _PasswordFormWidget();
class PasswordFormWidget extends StatefulWidget {
const PasswordFormWidget({super.key});

@override
State<_PasswordFormWidget> createState() => _PasswordFormWidgetState();
State<PasswordFormWidget> createState() => _PasswordFormWidgetState();
}

class _PasswordFormWidgetState extends State<_PasswordFormWidget> {
class _PasswordFormWidgetState extends State<PasswordFormWidget> {
final _formState = GlobalKey<FormState>();
final _textFormFieldController = TextEditingController();

Expand Down

0 comments on commit 61271eb

Please sign in to comment.