我想要将我创建的SizedBox居中,所以我用Center小部件将其包装起来,如下所示:
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
title: 'My app',
home: SafeArea(
child: MyScaffold(),
),
),
);
}
class MyScaffold extends StatelessWidget {
const MyScaffold({super.key});
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: [
TextInputWidget(),
],
),
);
}
}
class TextInputWidget extends StatelessWidget {
const TextInputWidget({super.key});
@override
Widget build(BuildContext context) {
return Row(
children: [
Center(
child: SizedBox(
width: 200.0,
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter a search term',
),
),
),
),
],
);
}
}
但不幸的是,它不起作用,正如您在下图中看到的那样,SizedBox仍然位于窗口的左侧:
我一直在寻找答案,但还没有找到.
对此有什么解决方案吗?
谢谢