我試圖在 Flutter 的列中實作兩個均勻間隔的按鈕。在重復小部件兩次時,第一個按鈕將縮小特定寬度。檢查時發現了這個。
我無法確定這個未知寬度的原因。這是供參考的代碼。
import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('Findo', style: Theme.of(context).textTheme.subtitle1),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () => {print('pressed')},
child: Text(
'Store Login',
style: Theme.of(context).textTheme.bodyText1,
),
style: ElevatedButton.styleFrom(
padding: const EdgeInsetsDirectional.fromSTEB(
100, 20, 100, 20),
primary: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(50.0)))),
),
ElevatedButton(
onPressed: () => {print('pressed')},
child: Text(
'Customer Login',
style: Theme.of(context).textTheme.bodyText1,
),
style: ElevatedButton.styleFrom(
padding: const EdgeInsetsDirectional.fromSTEB(
100, 20, 100, 20),
primary: Theme.of(context).accentColor,
shape: const RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(50.0)))),
)
],
)
],
),
),
),
);
}
}
uj5u.com熱心網友回復:
ElevatedButton沒有高度或寬度限制。就內部內容而言,它占用空間或(寬度和高度)。在您的情況下Store,Customer長度不同。所以客戶按鈕的寬度比商店大。你可以用一個容器包裹按鈕,并給它們一個像這樣的寬度 -
Container(
width: 300,
child: ElevatedButton(
onPressed: () => {print('pressed')},
child: Text(
'Store Login',
style: Theme.of(context).textTheme.bodyText1,
),
style: ElevatedButton.styleFrom(
padding: const EdgeInsetsDirectional.fromSTEB(
100, 20, 100, 20),
primary: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(50.0)))),
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421135.html
標籤:
