Skip to content

Commit c76a410

Browse files
committed
Improvement of the example app with a programmatically example
1 parent a736b83 commit c76a410

1 file changed

Lines changed: 100 additions & 56 deletions

File tree

example/lib/screens/forms/password_box.dart

Lines changed: 100 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,119 @@ import 'package:example/widgets/card_highlight.dart';
22
import 'package:example/widgets/page.dart';
33
import 'package:fluent_ui/fluent_ui.dart';
44

5-
class PasswordBoxPage extends ScrollablePage {
6-
PasswordBoxPage({super.key});
5+
class PasswordBoxPage extends StatefulWidget {
6+
const PasswordBoxPage({super.key});
77

88
@override
9-
Widget buildHeader(BuildContext context) {
10-
return const PageHeader(title: Text('PasswordBox'));
11-
}
9+
State<PasswordBoxPage> createState() => _PasswordBoxPageState();
10+
}
11+
12+
class _PasswordBoxPageState extends State<PasswordBoxPage> with PageMixin {
13+
bool disabled = false;
14+
PasswordRevealMode revealMode = PasswordRevealMode.peek;
1215

1316
@override
14-
List<Widget> buildScrollable(BuildContext context) {
15-
return [
16-
const Text(
17-
'The PasswordBox is almost identical to the TextBox. But the character'
18-
' is obfuscated by default and a button in the suffix allow the user to '
19-
'show briefly the password in plain text.',
17+
Widget build(BuildContext context) {
18+
return ScaffoldPage.scrollable(
19+
header: PageHeader(
20+
title: const Text('NumberBox'),
21+
commandBar: ToggleSwitch(
22+
checked: disabled,
23+
onChanged: (v) {
24+
setState(() => disabled = v);
25+
},
26+
content: const Text('Disabled'),
27+
),
2028
),
21-
subtitle(
22-
content: const Text('A simple PasswordBox in peek mode (default)')),
23-
CardHighlight(
24-
child: Row(children: const [
25-
Expanded(child: PasswordBox()),
26-
SizedBox(width: 10.0),
27-
Expanded(
28-
child: PasswordBox(
29-
enabled: false,
30-
placeholder: 'Disabled PasswordBox',
31-
),
32-
)
33-
]),
34-
codeSnippet: '''PasswordBox()''',
35-
),
36-
subtitle(content: const Text('A simple PasswordBox in peekAlways mode')),
37-
CardHighlight(
38-
child: Row(children: const [
39-
Expanded(
40-
child: PasswordBox(
41-
revealMode: PasswordRevealMode.peekAlways,
42-
)),
43-
]),
44-
codeSnippet: '''PasswordBox(
29+
children: [
30+
const Text(
31+
'The PasswordBox is almost identical to the TextBox. But the character'
32+
' is obfuscated by default and a button in the suffix allow the user to '
33+
'show briefly the password in plain text.',
34+
),
35+
subtitle(
36+
content: const Text('A simple PasswordBox in peek mode (default)')),
37+
CardHighlight(
38+
child: Row(children: [
39+
Expanded(
40+
child: PasswordBox(
41+
enabled: !disabled,
42+
)),
43+
]),
44+
codeSnippet: '''PasswordBox()''',
45+
),
46+
subtitle(
47+
content: const Text('A simple PasswordBox in peekAlways mode')),
48+
CardHighlight(
49+
child: Row(children: [
50+
Expanded(
51+
child: PasswordBox(
52+
enabled: !disabled,
53+
revealMode: PasswordRevealMode.peekAlways,
54+
)),
55+
]),
56+
codeSnippet: '''PasswordBox(
4557
revealMode: PasswordRevealMode.peekAlways,
4658
)''',
47-
),
48-
subtitle(
49-
content: const Text(
50-
'A simple PasswordBox in visible (left) and hidden (right) mode')),
51-
CardHighlight(
52-
child: Row(children: const [
53-
Expanded(
59+
),
60+
subtitle(
61+
content: const Text(
62+
'A simple PasswordBox in visible (left) and hidden (right) mode')),
63+
CardHighlight(
64+
child: Row(children: [
65+
Expanded(
66+
child: PasswordBox(
67+
enabled: !disabled,
68+
revealMode: PasswordRevealMode.visible,
69+
placeholder: 'Visible Password',
70+
)),
71+
const SizedBox(width: 10.0),
72+
Expanded(
5473
child: PasswordBox(
55-
revealMode: PasswordRevealMode.visible,
56-
placeholder: 'Visible Password',
57-
)),
58-
SizedBox(width: 10.0),
59-
Expanded(
60-
child: PasswordBox(
61-
revealMode: PasswordRevealMode.hidden,
62-
placeholder: 'Hidden Password',
63-
),
64-
)
65-
]),
66-
codeSnippet: '''PasswordBox(
74+
enabled: !disabled,
75+
revealMode: PasswordRevealMode.hidden,
76+
placeholder: 'Hidden Password',
77+
),
78+
)
79+
]),
80+
codeSnippet: '''PasswordBox(
6781
revealMode: PasswordRevealMode.visible,
6882
);
6983
7084
PasswordBox(
7185
revealMode: PasswordRevealMode.hidden,
7286
);''',
73-
),
74-
];
87+
),
88+
subtitle(content: const Text('Update programmatically the visibility')),
89+
CardHighlight(
90+
child: Row(children: [
91+
Expanded(
92+
child: PasswordBox(
93+
enabled: !disabled,
94+
revealMode: revealMode,
95+
),
96+
),
97+
const SizedBox(width: 10),
98+
SizedBox(
99+
// width: 50,
100+
child: ComboBox<PasswordRevealMode>(
101+
onChanged: (e) {
102+
setState(() {
103+
revealMode = e ?? PasswordRevealMode.peek;
104+
});
105+
},
106+
value: revealMode,
107+
items: PasswordRevealMode.values.map((e) {
108+
return ComboBoxItem(child: Text(e.name), value: e);
109+
}).toList(),
110+
),
111+
),
112+
]),
113+
codeSnippet: '''PasswordBox(
114+
revealMode: revealMode,
115+
)''',
116+
),
117+
],
118+
);
75119
}
76120
}

0 commit comments

Comments
 (0)