为了使 Card 组件占据最大可用空间,可以使用 SizedBox 组件将其包裹,并将高度和宽度设置为 double.infinity。以下是更新后的代码:

class CalllogAddPage extends StatefulWidget {
  const CalllogAddPage({Key? key}) : super(key: key);

  @override
  State<CalllogAddPage> createState() => _CalllogAddPageState();
}

class _CalllogAddPageState extends State<CalllogAddPage> {
  final GlobalKey _formKey = GlobalKey<FormState>();

  Map<String, dynamic> _param = {};

  String? path;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('通话信息上传'),
      ),
      body: Container(
        alignment: Alignment.topCenter,
        child: SizedBox(
          height: double.infinity,
          width: double.infinity,
          child: Card(
            margin: EdgeInsets.only(left: 30, top: 20, right: 30, bottom: 50),
            child: Form(
              key: _formKey,
              child: Container(
                margin: EdgeInsets.all(10),
                child: Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      TextButton(
                        onPressed: () async {
                          FilePickerResult? result = await FilePicker.platform.pickFiles(
                            dialogTitle: '录音选择',
                            type: FileType.audio,
                          );
                          if (result != null) {
                            String? file = result.files.single.path;
                            path = file;
                            setState(() {});
                          } else {
                            // User canceled the picker
                          }
                        },
                        child: Text('文件选择'),
                      ),
                      SizedBox(height: 15),
                      Container(
                        child: Text('$path'),
                      ),
                      SizedBox(height: 15),
                      ElevatedButton(
                        onPressed: () {
                          FormState _form = _formKey.currentState as FormState;
                          _form.save();
                          if (_form.validate()) {
                            if (_param.length < 3) {
                              EasyLoading.showError('请填写完内容');
                              return;
                            }
                          }
                        },
                        child: Text('上传'),
                      )
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

通过将 Card 组件包裹在 SizedBox 组件中,并设置其高度和宽度为 double.infinity,可以使 Card 组件占据整个屏幕可用空间。


原文地址: https://www.cveoy.top/t/topic/mRfL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录