|
| 1 | +import 'package:example/widgets/card_highlight.dart'; |
| 2 | +import 'package:example/widgets/page.dart'; |
| 3 | +import 'package:fluent_ui/fluent_ui.dart'; |
| 4 | + |
| 5 | +class PasswordBoxPage extends StatefulWidget { |
| 6 | + const PasswordBoxPage({super.key}); |
| 7 | + |
| 8 | + @override |
| 9 | + State<PasswordBoxPage> createState() => _PasswordBoxPageState(); |
| 10 | +} |
| 11 | + |
| 12 | +class _PasswordBoxPageState extends State<PasswordBoxPage> with PageMixin { |
| 13 | + bool disabled = false; |
| 14 | + PasswordRevealMode revealMode = PasswordRevealMode.peek; |
| 15 | + |
| 16 | + @override |
| 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 | + ), |
| 28 | + ), |
| 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( |
| 57 | + revealMode: PasswordRevealMode.peekAlways, |
| 58 | +)''', |
| 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( |
| 73 | + child: PasswordBox( |
| 74 | + enabled: !disabled, |
| 75 | + revealMode: PasswordRevealMode.hidden, |
| 76 | + placeholder: 'Hidden Password', |
| 77 | + ), |
| 78 | + ) |
| 79 | + ]), |
| 80 | + codeSnippet: '''PasswordBox( |
| 81 | + revealMode: PasswordRevealMode.visible, |
| 82 | +); |
| 83 | +
|
| 84 | +PasswordBox( |
| 85 | + revealMode: PasswordRevealMode.hidden, |
| 86 | +);''', |
| 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 | + ); |
| 119 | + } |
| 120 | +} |
0 commit comments