【问题标题】:why cant my card be placed in the middle of the screen in flutter为什么我的卡片不能颤动地放在屏幕中间
【发布时间】:2022-11-23 01:52:19
【问题描述】:

我尝试在类文件中放置几个​​中心,只会出现 2 个问题,一个是中心不起作用,另一个会出错,我的代码中是否放置了错误? 我不确定我的小部件出了什么问题或我与小部件混淆了


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:hupcarwashemployee/user_model/employee.dart';

import '../user_model/assignment.dart';

class UpdateAssignStatus extends StatefulWidget {
  final String id;
  UpdateAssignStatus(
      {required this.id});

  @override
  State<UpdateAssignStatus> createState() => _UpdateAssignStatusState();
}

class _UpdateAssignStatusState extends State<UpdateAssignStatus> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Assign'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            StreamBuilder<List<Assignment>>(
              stream: read(widget.id.toString()),
              builder: (context, snapshot){
                if (snapshot.connectionState == ConnectionState.waiting) {
                  return const Center(
                    child: CircularProgressIndicator(),
                  );
                }
                if (snapshot.hasError) {
                  return const Center(
                    child: Text("some error occured"),
                  );
                }
                if(snapshot.hasData){
                  final userData = snapshot.data;
                  return Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(
                          height: 400,
                          width: 300,
                          child: ListView.builder(
                            itemCount: userData!.length,
                            itemBuilder: (context, index){
                              final assignment = userData[index];
                              return SizedBox(
                                height: 400,
                                width: 300,
                                child: Card(
                                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                                  child: Column(
                                    children: [
                                      Table(
                                        children: [
                                          TableRow(
                                              children: [
                                                const Center(child: Text('Date', style: TextStyle(fontFamily: 'MonMed'),)),
                                                Text(': ${assignment.date.toString()}', style: const TextStyle(fontFamily: 'MonMed'),),
                                              ]
                                          ),
                                          const TableRow(children: [SizedBox(height: 10,), SizedBox(height: 10,)]),
                                          TableRow(
                                              children: [
                                                const Center(child: Text('Customer Name', style: TextStyle(fontFamily: 'MonMed'),)),
                                                Text(': ${assignment.custName.toString()}', style: const TextStyle(fontFamily: 'MonMed'),),
                                              ]
                                          ),
                                          const TableRow(children: [SizedBox(height: 10,), SizedBox(height: 10,)]),
                                          TableRow(
                                              children: [
                                                const Center(child: Text('Car Name', style: TextStyle(fontFamily: 'MonMed'),)),
                                                Text(': ${assignment.carName.toString()}', style: const TextStyle(fontFamily: 'MonMed'),),
                                              ]
                                          ),
                                          const TableRow(children: [SizedBox(height: 10,), SizedBox(height: 10,)]),
                                          TableRow(
                                              children: [
                                                const Center(child: Text('Car Plate', style: TextStyle(fontFamily: 'MonMed'),)),
                                                Text(': ${assignment.carPlate.toString()}', style: const TextStyle(fontFamily: 'MonMed'),),
                                              ]
                                          ),
                                          const TableRow(children: [SizedBox(height: 10,), SizedBox(height: 10,)]),
                                        ],
                                      )
                                    ],
                                  ),
                                ),
                              );
                            },
                          )
                      ),
                    ],
                  );
                }
                return const Center(
                  child: CircularProgressIndicator(),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
  static Stream<List<Assignment>> read(String type) {
    final serviceCollection = FirebaseFirestore.instance.collection('Assignment').where('id',isEqualTo: type);
    return serviceCollection.snapshots().map((querySnapshot) =>
        querySnapshot.docs.map((e) => Assignment.fromSnapshot(e)).toList());
  }
}





这个是我想看到的用户界面,就像在中间,一张带有信息的卡片

【问题讨论】:

  • 请你分享错误
  • 你想让你的清单居中吗? @林

标签: flutter user-interface widget center card


【解决方案1】:

warp tour main column with center 然后把这个mainAxisAlignment: MainAxisAlignment.center,放在上面

请你分享你的错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 2021-07-07
    相关资源
    最近更新 更多