完成基础学习

This commit is contained in:
daodaoshi 2025-01-23 21:51:27 +08:00
parent d4526da56d
commit 083600878e
30 changed files with 255 additions and 34 deletions

View File

@ -41,3 +41,11 @@ samples, guidance on mobile development, and a full API reference.
- 写布局前先把结构列好用函数拆分用_bulid开头表示私有布局函数 - 写布局前先把结构列好用函数拆分用_bulid开头表示私有布局函数
- 在使用elevatedbutton时使用style将样式还原在外面套一层Container作为装饰更方便配置 - 在使用elevatedbutton时使用style将样式还原在外面套一层Container作为装饰更方便配置
- 使用Navigator.pushReplacement 替换路由 - 使用Navigator.pushReplacement 替换路由
## 表单
- 表单TextField通过textfield.decoration进行装饰
- 使用prefixIcon、suffixIcon设置前置、后置图标
- 一些简单的验证可以放在TextField的onChanged中
- 注意在涉及到更新状态时使用setState
## 按钮组件
- 抽取公共组件放在commont里
- 公共组件外露的属性使用final修饰并在构造函数中

View File

@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=file:///C:/Users/24811/.gradle/wrapper/dists/gradle-6.7-all.zip # distributionUrl=file:///C:/Users/24811/.gradle/wrapper/dists/gradle-6.7-all.zip
# distributionUrl=file:///D:/Gradle/.gradle/wrapper/dists/gradle-6.7-all.zip distributionUrl=file:///D:/Gradle/.gradle/wrapper/dists/gradle-6.7-all.zip

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1,2 +1,9 @@
static const iconFavouritePng = 'assets/images/icon_favourite.png';
static const iconLockPng = 'assets/images/icon_lock.png';
static const iconMapPng = 'assets/images/icon_map.png';
static const iconOffersPng = 'assets/images/icon_offers.png';
static const iconOrderPng = 'assets/images/icon_order.png';
static const iconPaymentPng = 'assets/images/icon_payment.png';
static const iconUserPng = 'assets/images/icon_user.png';
static const logoPng = 'assets/images/logo.png'; static const logoPng = 'assets/images/logo.png';
static const welcomePng = 'assets/images/welcome.png'; static const welcomePng = 'assets/images/welcome.png';

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

BIN
assets/images/icon_lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

BIN
assets/images/icon_map.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

BIN
assets/images/icon_user.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

View File

@ -1,4 +1,12 @@
class AssetsImages { class AssetsImages {
static const iconFavouritePng = 'assets/images/icon_favourite.png';
static const iconLockPng = 'assets/images/icon_lock.png';
static const iconMapPng = 'assets/images/icon_map.png';
static const iconOffersPng = 'assets/images/icon_offers.png';
static const iconOrderPng = 'assets/images/icon_order.png';
static const iconPaymentPng = 'assets/images/icon_payment.png';
static const iconUserPng = 'assets/images/icon_user.png';
static const logoPng = 'assets/images/logo.png'; static const logoPng = 'assets/images/logo.png';
static const welcomePng = 'assets/images/welcome.png'; static const welcomePng = 'assets/images/welcome.png';
} }

View File

@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
class ButtonWidget extends StatelessWidget {
const ButtonWidget({
Key? key, this.text, this.width, this.height, this.radius, this.onPressed,
}) : super(key: key);
final String? text;
final double? width;
final double? height;
final double? radius;
final void Function()? onPressed;
@override
Widget build(BuildContext context) {
//Container
return Container(
//
height: height ?? double.infinity,
width: width ?? double.infinity,
//
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius ?? 32),
),
child: ElevatedButton(
onPressed: onPressed,
style: ButtonStyle(
elevation: MaterialStateProperty.all(0),
//0children尺寸
minimumSize: MaterialStateProperty.all(Size.zero)),
child: Text(text ?? "",
style: const TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w300,
)),
),
);
}
}

45
lib/common/button.dart Normal file
View File

@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
class ButtonWidget extends StatelessWidget {
const ButtonWidget({
Key? key,
this.text,
this.width,
this.height,
this.radius,
this.onPressed,
}) : super(key: key);
final String? text;
final double? width;
final double? height;
final double? radius;
final void Function()? onPressed;
@override
Widget build(BuildContext context) {
//Container
return ElevatedButton(
onPressed: onPressed,
style: ButtonStyle(
elevation: MaterialStateProperty.all(0),
//0children尺寸
minimumSize: MaterialStateProperty.all(Size(
width ?? double.infinity,
height ?? double.infinity,
)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius?? 32),
),
),
),
child: Text(text ?? "",
style: const TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w300,
)),
);
}
}

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'pages/splash.dart';
import 'pages/login.dart';
void main() { void main() {
@ -13,7 +12,7 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
home: const LoginPage(), home: const SplashPage(),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: ThemeData( theme: ThemeData(
// //

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_qucikstart/common/button.dart';
import '../common/app_colors.dart'; import '../common/app_colors.dart';
import '../common/assets.dart'; import '../common/assets.dart';
@ -11,9 +12,133 @@ class LoginPage extends StatefulWidget {
} }
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends State<LoginPage> {
// //
bool isUserNameValid = false;
//
Widget _buildForm() { Widget _buildForm() {
return Container(); return Container(
padding: const EdgeInsets.fromLTRB(20, 70, 20, 35),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(35),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Username or Email
const Text(
'Username or Email',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w300,
color: Color(0xFF838383),
),
),
const SizedBox(height: 16),
TextField(
//Onchange时检测输入是否有效
onChanged: (value) {
setState(() {
isUserNameValid = value.isNotEmpty && value.length > 6;
});
},
decoration: InputDecoration(
hintText: '@',
prefixIcon: Image.asset(
AssetsImages.iconUserPng,
width: 23,
height: 23,
),
suffixIcon: isUserNameValid == true
? const Icon(
Icons.done,
size: 24,
color: Colors.green,
)
: null,
),
),
const SizedBox(height: 36),
//password
const Text(
'Password',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w300,
color: Color(0xFF838383),
),
),
const SizedBox(height: 16),
TextField(
//
obscureText: true,
decoration: InputDecoration(
hintText: '6 digits',
prefixIcon: Image.asset(
AssetsImages.iconLockPng,
width: 19,
height: 26,
),
suffixIcon: TextButton(
onPressed: (() {}),
child: const Text(
'Forget?',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Color(0xFF0274BC),
),
),
),
),
),
const SizedBox(height: 30),
//Sign In btn
ButtonWidget(
text: "Sign In",
height: 57,
onPressed:(){}
),
const SizedBox(height: 16),
//Don't have an account? Sign up
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
const Text(
"Don't have an account?",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w300,
color: Color(0xFF171717),
),
),
//
TextButton(
onPressed: (() {}),
child: const Text(
"Sign up",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Color(0xFF0274bc),
),
),
)
],
)
//end
],
),
);
} }
// //

View File

@ -1,12 +1,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../common/assets.dart'; import '../common/assets.dart';
import '../common/button.dart';
import '../pages/login.dart';
class WelcomePage extends StatelessWidget { class WelcomePage extends StatelessWidget {
const WelcomePage({Key? key}) : super(key: key); const WelcomePage({Key? key}) : super(key: key);
// //
Widget _bulidBtns() { Widget _bulidBtns(BuildContext context) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row( child: Row(
@ -26,28 +28,13 @@ class WelcomePage extends StatelessWidget {
const Spacer(), const Spacer(),
//getstarted按钮 //getstarted按钮
//Container ButtonWidget(
Container( text: "Get Started",
height: 42,
width: 139, width: 139,
// height: 42,
clipBehavior: Clip.antiAlias, radius: 32,
decoration: BoxDecoration( onPressed: () => Navigator.push(context,
borderRadius: BorderRadius.circular(32), MaterialPageRoute(builder: ((context) => const LoginPage()))),
),
child: ElevatedButton(
onPressed: (() {}),
style: ButtonStyle(
elevation: MaterialStateProperty.all(0),
//0children尺寸
minimumSize: MaterialStateProperty.all(Size.zero)),
child: const Text('Get Started',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w300,
)),
),
), ),
], ],
), ),
@ -69,7 +56,7 @@ class WelcomePage extends StatelessWidget {
); );
} }
Widget _buildView() { Widget _buildView(BuildContext context) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@ -91,7 +78,7 @@ class WelcomePage extends StatelessWidget {
height: 70, height: 70,
), ),
// //
_bulidBtns(), _bulidBtns(context),
//end //end
], ],
@ -101,7 +88,7 @@ class WelcomePage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Center(child: _buildView()), body: Center(child: _buildView(context)),
); );
} }
} }