英文:
Why can't the buttons in the column be full-width, but the outside buttons can be full-width?
问题
这是两个相同的按钮。
外部按钮的宽度与页面的宽度相同。
内部按钮的宽度是可能的最小宽度。
我想让内部按钮的宽度与卡片相同,我该如何更改?
如何更新?
import 'package:flutter/material.dart';
class RoomListPage extends StatefulWidget {
const RoomListPage({Key? key}) : super(key: key);
@override
_RoomListPageState createState() => _RoomListPageState();
}
class _RoomListPageState extends State<RoomListPage> {
List roomList = [
{
"title": "卧室",
"type": "卧室",
"description": "这是卧室",
},
{
"title": "厨房",
"type": "厨房",
"description": "这是厨房",
},
{
"title": "浴室",
"type": "浴室",
"description": "这是浴室",
},
];
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: ListView(children: [
const SizedBox(height: 20),
ElevatedButton(onPressed: () {}, child: const Text('添加区域')), // 外部按钮 - 全宽度
const SizedBox(height: 20),
...roomList.map(
(room) => Column(
children: [
ElevatedButton(onPressed: () {}, child: const Text('添加区域')), // 内部按钮 - 最小宽度
Card(
child: Column(
children: [
Text(room['title'] as String),
Text(room['description'] as String),
],
)),
const SizedBox(height: 20)
],
),
),
]),
);
}
}
英文:
These are two identical buttons
The width of the outer button is the same as the width of the page
The width of the inner button is the smallest possible width
I want the inner button to be the same width as the card, how do I change this?
How do I update?
import 'package:flutter/material.dart';
class RoomListPage extends StatefulWidget {
const RoomListPage({Key? key}) : super(key: key);
@override
_RoomListPageState createState() => _RoomListPageState();
}
class _RoomListPageState extends State<RoomListPage> {
List roomList = [
{
"title": "bedroom",
"type": "bedroom",
"description": "this is bedroom",
},
{
"title": "kitchen",
"type": "kitchen",
"description": "this is kitchen",
},
{
"title": "bathroom",
"type": "bathroom",
"description": "this is bathroom",
},
];
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: ListView(children: [
const SizedBox(height: 20),
ElevatedButton(onPressed: () {}, child: const Text('Add region')), // outer button - full width
const SizedBox(height: 20),
...roomList.map(
(room) => Column(
children: [
ElevatedButton(onPressed: () {}, child: const Text('Add region')), // inner button - min width
Card(
child: Column(
children: [
Text(room['title'] as String),
Text(room['description'] as String),
],
)),
const SizedBox(height: 20)
],
),
),
]),
);
}
}
答案1
得分: 0
尝试将ElevatedButton包装在一个Row中。您可以在https://docs.flutter.dev/ui/layout/constraints了解更多关于Flutter约束的信息。
英文:
Try wrapping the ElevatedButton in a Row. You can learn more about Flutter constraints at https://docs.flutter.dev/ui/layout/constraints
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论