我正在嘗試為用戶創建一個組態檔螢屏,我想在Save Changes按鈕下方放置一個Spacer ,以便在此按鈕與其下方的其他 2 個按鈕(注銷和更改密碼)之間創建一些空間,但出于某種原因Spacer 不會在按鈕之間創建任何空間。我嘗試使用一個簡單的sizedBox來執行此操作,但我希望我的應用程式能夠回應,所以我不能使用這個“解決方案”。
誰能幫我?:)
我的構建小部件:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF263238),
body: SafeArea(
child: Center(
child: ListView(
children: [
Row(
children: [
Container(
margin: const EdgeInsets.only(top: 12),
child: IconButton(
icon: Image.asset(
"assets/images/back_icon.png",
height: 30,
width: 30,
),
iconSize: 40,
onPressed: () {
// Go to previews screen
Navigator.pop(context);
},
),
),
Container(
margin: const EdgeInsets.only(left: 8, top: 12),
child: const Text(
"My Profile",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 23),
),
),
const Spacer()
],
),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(top: 15, right: 10),
child: isProfilePictureEmpty
? _emptyProfilePicture(context)
: _profilePictureFromURL(context),
),
Container(
margin: const EdgeInsets.only(top: 20),
child: Column(
children: [
Container(
margin:
const EdgeInsets.only(left: 45.0, right: 40.0),
child: Row(
children: const [
Text("Username",
style: TextStyle(
color: Colors.grey, fontSize: 17)),
Spacer()
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color.fromARGB(255, 72, 92, 105)),
margin: const EdgeInsets.only(
top: 5.0, left: 40.0, right: 40.0),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
controller: usernameController,
onChanged: (usernameInput) {
setState(() {
username = usernameInput;
isSaveButtonEnabled = true;
});
},
cursorColor: Colors.black,
decoration: const InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 11, top: 11, right: 15),
hintText: "Username"),
),
)
],
)),
Container(
margin: const EdgeInsets.only(top: 20),
child: Column(
children: [
Container(
margin:
const EdgeInsets.only(left: 45.0, right: 40.0),
child: Row(
children: const [
Text("Email address",
style: TextStyle(
color: Colors.grey, fontSize: 17)),
Spacer()
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color.fromARGB(255, 72, 92, 105)),
margin: const EdgeInsets.only(
top: 5.0, left: 40.0, right: 40.0),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
controller: emailController,
onChanged: (emailInput) {
setState(() {
email = emailInput;
isSaveButtonEnabled = true;
});
},
cursorColor: Colors.black,
decoration: const InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 11, top: 11, right: 15),
hintText: "Email address"),
),
)
],
)),
const SizedBox(height: 30),
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed:
!isSaveButtonEnabled ? null : _saveProfileChanges,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.indigo),
child: Text("$saveButtonText",
style: const TextStyle(fontSize: 20)),
),
),
const Spacer(),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.indigo),
child: const Text("Change password",
style: TextStyle(fontSize: 20)),
),
),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed: () {
CoolAlert.show(
onConfirmBtnTap: logout,
onCancelBtnTap: () {
Navigator.of(context).pop();
},
context: context,
type: CoolAlertType.confirm,
text: 'Do you want to logout?',
confirmBtnText: 'Yes',
cancelBtnText: 'No',
confirmBtnColor: Colors.red,
);
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.red),
child: const Text("Logout", style: TextStyle(fontSize: 20)),
),
),
const Spacer(),
const Spacer(),
],
),
),
),
bottomNavigationBar: const Padding(
padding: EdgeInsets.fromLTRB(8, 16, 8, 16),
child: Text(
"Made by George Sepetadelis",
style: TextStyle(color: Colors.grey, fontSize: 18),
textAlign: TextAlign.center,
),
));
}
uj5u.com熱心網友回復:
通過使用“CustomScrollView”小部件,您可以實作您想要的。


由于缺少您的代碼,我洗掉了一些回呼函式體和條件狀態代碼。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF263238),
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
Row(
children: [
Container(
margin: const EdgeInsets.only(top: 12),
child: IconButton(
icon: Image.asset(
"assets/images/back_icon.png",
height: 30,
width: 30,
),
iconSize: 40,
onPressed: () {
// Go to previews screen
Navigator.pop(context);
},
),
),
Container(
margin: const EdgeInsets.only(left: 8, top: 12),
child: const Text(
"My Profile",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 23),
),
),
const Spacer()
],
),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(top: 15, right: 10),
),
Container(
margin: const EdgeInsets.only(top: 20),
child: Column(
children: [
Container(
margin:
const EdgeInsets.only(left: 45.0, right: 40.0),
child: Row(
children: const [
Text("Username",
style: TextStyle(
color: Colors.grey, fontSize: 17)),
Spacer()
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color.fromARGB(255, 72, 92, 105)),
margin: const EdgeInsets.only(
top: 5.0, left: 40.0, right: 40.0),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
// controller: usernameController,
onChanged: (usernameInput) {
// setState(() {
// username = usernameInput;
// isSaveButtonEnabled = true;
// });
},
cursorColor: Colors.black,
decoration: const InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 11, top: 11, right: 15),
hintText: "Username"),
),
)
],
),
),
Container(
margin: const EdgeInsets.only(top: 20),
child: Column(
children: [
Container(
margin: const EdgeInsets.only(
left: 45.0, right: 40.0),
child: Row(
children: const [
Text("Email address",
style: TextStyle(
color: Colors.grey, fontSize: 17)),
Spacer()
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color:
const Color.fromARGB(255, 72, 92, 105)),
margin: const EdgeInsets.only(
top: 5.0, left: 40.0, right: 40.0),
child: TextFormField(
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
// controller: emailController,
onChanged: (emailInput) {
// setState(() {
// email = emailInput;
// isSaveButtonEnabled = true;
// });
},
cursorColor: Colors.black,
decoration: const InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15,
bottom: 11,
top: 11,
right: 15),
hintText: "Email address"),
),
)
],
)),
const SizedBox(height: 30),
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.indigo),
child: Text("saveButtonText",
style: const TextStyle(fontSize: 20)),
),
),
],
),
),
SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.indigo),
child: const Text("Change password",
style: TextStyle(fontSize: 20)),
),
),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(left: 40, right: 40),
width: 370,
height: 50,
child: ElevatedButton(
onPressed: () {
// CoolAlert.show(
// onConfirmBtnTap: logout,
// onCancelBtnTap: () {
// Navigator.of(context).pop();
// },
// context: context,
// type: CoolAlertType.confirm,
// text: 'Do you want to logout?',
// confirmBtnText: 'Yes',
// cancelBtnText: 'No',
// confirmBtnColor: Colors.red,
// );
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
primary: Colors.red),
child: const Text("Logout",
style: TextStyle(fontSize: 20)),
),
),
],
),
),
],
),
),
bottomNavigationBar: const Padding(
padding: EdgeInsets.fromLTRB(8, 16, 8, 16),
child: Text(
"Made by George Sepetadelis",
style: TextStyle(color: Colors.grey, fontSize: 18),
textAlign: TextAlign.center,
),
));
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/449690.html
上一篇:如何在顫動中適合列/行表影像內容
