Flutter 登录页-05

源码下载

依赖包

  • google_fonts

知识点

页面增加背景图片

1
2
3
4
5
6
7
8
9
10
11
12
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/bg.png"),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
body:...
),
)

圆角矩形按钮

外层使用 SizedBox 控制按钮尺寸,内部使用 MaterialButton 做按钮。

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

代码实现

main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import 'package:flutter/material.dart';
import 'package:login_05/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,
),
debugShowCheckedModeBanner: false,
home: const 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
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

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

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

class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/bg.png"),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
body: Column(
children: [
const SizedBox(height: 75),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Code\nDecoders",
style: GoogleFonts.montserrat(
fontSize: 40,
color: Colors.white,
fontWeight: FontWeight.normal,
),
),
Text(
"|",
style: GoogleFonts.montserrat(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w200,
),
),
Text(
"Login UI",
style: GoogleFonts.montserrat(
fontSize: 20,
color: Colors.white,
),
),
],
),
const SizedBox(height: 400),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 45,
width: 120,
child: MaterialButton(
onPressed: () {},
child: const Text(
"SIGN IN",
style: TextStyle(
fontFamily: "SFUITest",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
color: const Color(0xff061420),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
SizedBox(
height: 45,
width: 120,
child: MaterialButton(
onPressed: () {},
child: const Text(
"SIGN UP",
style: TextStyle(
fontFamily: "SFUITest",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
const SizedBox(height: 17),
const Center(
child: Text(
"By continuing,you agree to our Terms and",
style: TextStyle(
fontFamily: "SFUITest",
fontSize: 13,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
),
const Center(
child: Text(
"Conditions",
style: TextStyle(
fontFamily: "SFUITest",
fontSize: 13,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
),
],
),
),
);
}
}