/
main.dart
executable file
·154 lines (150 loc) · 5.45 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import 'package:flutter/material.dart';
import 'package:passwordfield/passwordfield.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.red,
colorScheme:
ThemeData.light().colorScheme.copyWith(primary: Colors.red)),
home: PasswordApp(),
);
}
}
class PasswordApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Scaffold(
appBar: AppBar(
title: const Text('PasswordField Demo'),
),
body: ListView(
children: <Widget>[
const SizedBox(
height: 20,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: PasswordField(
backgroundColor: Colors.red.shade100,
controller: TextEditingController(text: 'password'),
errorMessage:
'required at least 1 letter and number 5+ chars',
passwordConstraint: r'^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{5,}$',
passwordDecoration: PasswordDecoration(
inputPadding: const EdgeInsets.symmetric(horizontal: 10),
suffixIcon: const Icon(
Icons.not_accessible,
color: Colors.grey,
),
inputStyle: const TextStyle(
fontSize: 14,
),
),
hintText: 'Password',
onChanged: (x) {
print(x);
},
border: PasswordBorder(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
BorderSide(width: 2, color: Colors.red.shade200),
),
),
),
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: PasswordField(
color: Colors.blue,
passwordConstraint: r'.*[@$#.*].*',
passwordDecoration: PasswordDecoration(),
// hintText: 'must have special characters',
border: PasswordBorder(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue.shade100,
),
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue.shade100,
),
borderRadius: BorderRadius.circular(12),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
BorderSide(width: 2, color: Colors.red.shade200),
),
),
errorMessage:
'must contain special character either . * @ # \$',
),
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: PasswordField(
backgroundColor: Colors.blue.withOpacity(0.2),
errorMessage: '''
- A uppercase letter
- A lowercase letter
- A digit
- A special character
- A minimum length of 8 characters
''',
hintText: 'Default password constraint ',
passwordDecoration: PasswordDecoration(
inputPadding: const EdgeInsets.symmetric(horizontal: 20),
),
border: PasswordBorder(
border: OutlineInputBorder(
borderSide:
const BorderSide(width: 0, color: Colors.grey),
borderRadius: BorderRadius.circular(25.7)),
focusedBorder: OutlineInputBorder(
borderSide:
const BorderSide(width: 0, color: Colors.grey),
borderRadius: BorderRadius.circular(25.7),
),
enabledBorder: OutlineInputBorder(
borderSide:
const BorderSide(width: 0, color: Colors.grey),
borderRadius: BorderRadius.circular(25.7),
),
),
),
),
],
)),
);
}
}