在屏幕上按比例显示内容
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: FractionallySizedBox(
widthFactor: 0.8,
child: TextButton(
child: Text("Press Here"),
onPressed: null,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green),
),
),
),
),
),
);
}
}
该博客展示了如何在Flutter应用中使用FractionallySizedBox widget来实现内容按比例在屏幕上显示。代码示例中,创建了一个宽度占屏幕80%的TextButton,背景颜色为绿色,点击事件为空。
2155

被折叠的 条评论
为什么被折叠?



