Flutter 登录页-04

源码下载

知识点

背景图增加黑色滤镜

1
2
3
4
5
6
7
8
9
10
11
12
13
return Container(
// 带黑色滤镜的背景图
decoration: BoxDecoration(
image: DecorationImage(
image: const AssetImage('assets/bg.png'),
fit: BoxFit.fill,
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.4),
BlendMode.darken,
),
),
),
);

圆角矩形区域

1
2
3
4
5
6
7
8
9
10
11
Card(
elevation: 10,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Container(
width: double.infinity,
height: 200,
),
)

圆角矩形输入框

关键要同时设置下面几个属性

  1. border
  2. enabledBorder
  3. errorBorder
  4. focusedBorder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
TextFormField(
obscureText: true,
decoration: InputDecoration(
filled:true,
fillColor: const Color(0xfff5f9f6),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.red),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.red),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.red),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.red),
),
),
),

圆角矩形按钮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SizedBox(
height: 56,
width: 120,
child: MaterialButton(
onPressed: () {},
child: const Text(
"Sign up",
style: TextStyle(
fontFamily: "SFUIText",
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xff293036),
),
),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),

原形头像

1
2
3
4
5
CircleAvatar(
child: Image.asset("assets/profile.png"),
radius: 80,
backgroundColor: Colors.transparent,
),

最终代码

main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import 'package:flutter/material.dart';
import 'package:login_04/homepage.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage());
}
}
homepage.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
final _formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context) {
return Container(
// 带黑色滤镜的背景图
decoration: BoxDecoration(
image: DecorationImage(
image: const AssetImage('assets/bg.png'),
fit: BoxFit.fill,
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.4),
BlendMode.darken,
),
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
// 内容区域 20内边距
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 68),
// 标题
Text(
"Welcome Back,\nKunal Jain!",
style: TextStyle(
fontFamily: "SFUIText",
fontSize: 24,
fontWeight: FontWeight.w600,
color: Colors.white.withOpacity(0.8),
),
),
const SizedBox(height: 230),
Card(
elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
// 表单
child: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 104),
// 密码输入框
TextFormField(
obscureText: true,
decoration: InputDecoration(
filled: true,
fillColor: const Color(0xfff5f9f6),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.transparent),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.transparent),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.transparent),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.transparent),
),
hintText: "Please enter password",
hintStyle: const TextStyle(
fontFamily: "SFUIText",
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xff696e72),
),
),
),
const SizedBox(height: 20),
const Center(
child: Text(
"Forgot Password?",
style: TextStyle(
fontFamily: "SFUIText",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff1bbdc4),
),
),
),
const SizedBox(height: 33),
],
),
),
),
),
const SizedBox(height: 35),
// 按钮区域
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// sign up 按钮
SizedBox(
height: 56,
width: 120,
child: MaterialButton(
onPressed: () {},
child: const Text(
"Sign up",
style: TextStyle(
fontFamily: "SFUIText",
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xff293036),
),
),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
// sign in 按钮
SizedBox(
height: 56,
width: 120,
child: MaterialButton(
onPressed: () {},
child: const Text(
"Sign in",
style: TextStyle(
fontFamily: "SFUIText",
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
color: const Color(0xff1bbdc4),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
],
),
// 头像
Center(
child: Padding(
padding: const EdgeInsets.only(top: 290),
child: CircleAvatar(
child: Image.asset("assets/profile.png"),
radius: 80,
backgroundColor: Colors.transparent,
),
),
),
],
),
),
),
);
}
}