图片自适应

This commit is contained in:
daodaoshi 2025-01-21 23:56:47 +08:00
parent 5ff5b8e28c
commit f66c0f247c
12 changed files with 74 additions and 10 deletions

View File

@ -32,3 +32,7 @@ samples, guidance on mobile development, and a full API reference.
- 使用future.delayed实现倒计时注意使用async - 使用future.delayed实现倒计时注意使用async
- 使用三目运算符控制显示 - 使用三目运算符控制显示
- 将相同组件抽出 - 将相同组件抽出
## 图片自适应
- 在main中使用theme设置全局样式
- 在padding中使用edgeinsets.symmetric设置水平间距
- image中使用fit Boxfit来设置宽高适配

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

View File

@ -1 +1,2 @@
static const logo_3xPng = 'assets/images/logo@3x.png'; static const logoPng = 'assets/images/logo.png';
static const welcomePng = 'assets/images/welcome.png';

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
assets/images/welcome.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -1,4 +1,4 @@
class AssetsImages{ class AssetsImages {
static const logopang = 'assets/images/logo@3x.png'; static const logoPng = 'assets/images/logo.png';
static const welcomePng = 'assets/images/welcome.png';
} }

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'pages/splash.dart'; import 'pages/welcome.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -11,9 +11,12 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const MaterialApp( return MaterialApp(
home: SplashPage(), home: const WelcomePage(),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'Poppins',
),
); );
} }
} }

View File

@ -57,7 +57,7 @@ class _SplashPageState extends State<SplashPage> {
// //
Image.asset( Image.asset(
AssetsImages.logopang, AssetsImages.logoPng,
width: 84, width: 84,
height: 80, height: 80,
) )
@ -71,7 +71,7 @@ class _SplashPageState extends State<SplashPage> {
text, text,
style: const TextStyle( style: const TextStyle(
fontSize: 19, fontSize: 19,
fontFamily: 'Poppins', // fontFamily: 'Poppins',
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.white, color: Colors.white,
height: 22 / 19, height: 22 / 19,

56
lib/pages/welcome.dart Normal file
View File

@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import '../common/assets.dart';
class WelcomePage extends StatelessWidget {
const WelcomePage({Key? key}) : super(key: key);
Padding _bulidText() {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 38),
child: Text(
'Browse & Oder All Products at Any Time',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xff2B2A2A),
height: 23 / 20,
),
),
);
}
Widget _buildView() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
_bulidText(),
const SizedBox(
height: 70,
),
//
Image.asset(AssetsImages.welcomePng,
height: 300,
//
width: double.infinity,
fit: BoxFit.fitWidth),
//
Container(),
//end
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: _buildView()),
);
}
}