简体   繁体   中英

SingleChildScrollView not working flutter

Hello friends I am learning to build apps in Flutter.Im creating a application in flutter and I want to implement SingleChildScrollView correctly in my code. How i can do that? any help please? Thank you in advance friends

My Code:

@override
  Widget build(BuildContext context) {
    return SafeArea(
        minimum: const EdgeInsets.only(
            top: 20.0, right: 5.0, left: 5.0, bottom: 10.0),
        child: Center(
            child: Scaffold(
                backgroundColor: Color(0xFFF6F7F8),
                body: Stack(
                  children: [
                    Container(
                      child: SingleChildScrollView(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Container(
                                  padding: EdgeInsets.all(10),
                                  child: ElevatedButton.icon(
                                    style: ElevatedButton.styleFrom(
                                        primary: KBlue,
                                        shape: RoundedRectangleBorder(
                                            borderRadius:
                                                BorderRadius.circular(30))),
                                    onPressed: () {
                                      showDialog(
                                        context: context,
                                        builder: (BuildContext context) =>
                                            _addNewBox(context),
                                      );
                                    },
                                    label: Text(
                                      'Ajouter un nouveau box',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                    icon: Icon(
                                      CommunityMaterialIcons.plus,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                            FutureBuilder(
                                future: fetchBoxes(),
                                builder: (BuildContext context,
                                    AsyncSnapshot<List<Box>> snapshot) {
                                  switch (snapshot.connectionState) {
                                    case ConnectionState.none:
                                      return Text('no connection');
                                    case ConnectionState.active:
                                    case ConnectionState.waiting:
                                      return Center(
                                        child: CircularProgressIndicator(),
                                      );
                                      break;
                                    case ConnectionState.done:
                                      if (snapshot.hasError) {
                                        return Text('error');
                                      } else {
                                        if (snapshot.hasData) {
                                          return ListView.builder(
                                            shrinkWrap: true,
                                            itemCount: snapshot.data.length,
                                            itemBuilder: (BuildContext context,
                                                int position) {
                                              return Card(
                                                  child: Column(
                                                mainAxisSize: MainAxisSize.min,
                                                children: [
                                                  Padding(
                                                      padding: EdgeInsets.only(
                                                        left: 10,
                                                        right: 10,
                                                      ),
                                                      child: ExpansionTile(
                                                        tilePadding:
                                                            EdgeInsets.only(
                                                                left: 10),
                                                        title: Text(
                                                          'Box 1',
                                                          style: TextStyle(
                                                              fontSize: 18,
                                                              fontWeight:
                                                                  FontWeight
                                                                      .w500),
                                                        ),

                                                        // backgroundColor: Colors.white,
                                                        children: [
                                                          Row(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            children: [
                                                              Text(
                                                                'Identifient :',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF01153D),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                              SizedBox(
                                                                width: 20,
                                                              ),
                                                              Text(
                                                                '123456789321',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF848586),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                          SizedBox(
                                                            height: 20,
                                                          ),
                                                          Row(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .start,
                                                            children: [
                                                              Text(
                                                                'Nom :',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF01153D),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                              Text(
                                                                'Box 1',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF848586),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                          SizedBox(
                                                            height: 20,
                                                          ),
                                                          Row(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .start,
                                                            children: [
                                                              Text(
                                                                'Propriétaire :',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF01153D),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                              Text(
                                                                '+216 24 648 834',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF848586),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                          SizedBox(
                                                            height: 20,
                                                          ),
                                                          Row(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .start,
                                                            children: [
                                                              Text(
                                                                'Adresse :',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF01153D),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                              Text(
                                                                'Grand Tunis',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xFF848586),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w400,
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                          SizedBox(
                                                            height: 20,
                                                          ),
                                                          Row(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceEvenly,
                                                            children: [
                                                              IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .circle_edit_outline,
                                                                  size: 30.0,
                                                                  color: Color(
                                                                      0xFFDEB522),
                                                                ),
                                                                onPressed: () {
                                                                  showDialog(
                                                                    context:
                                                                        context,
                                                                    builder: (BuildContext
                                                                            context) =>
                                                                        _buildNamePopupDialog(
                                                                            context),
                                                                  );
                                                                },
                                                              ),
                                                              IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .account_edit_outline,
                                                                  size: 30.0,
                                                                  color: Color(
                                                                      0xFFDEB522),
                                                                ),
                                                                onPressed: () {
                                                                  showDialog(
                                                                    context:
                                                                        context,
                                                                    builder: (BuildContext
                                                                            context) =>
                                                                        _buildPopupDialog(
                                                                            context),
                                                                  );
                                                                },
                                                              ),
                                                              IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .map_marker_circle,
                                                                  size: 30.0,
                                                                  color: Color(
                                                                      0xFFDEB522),
                                                                ),
                                                                onPressed: () {
                                                                  showDialog(
                                                                    context:
                                                                        context,
                                                                    builder: (BuildContext
                                                                            context) =>
                                                                        _buildAdressePopupDialog(
                                                                            context),
                                                                  );
                                                                },
                                                              ),
                                                              IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .delete_empty,
                                                                  size: 30.0,
                                                                  color: Color(
                                                                      0xFFDEB522),
                                                                ),
                                                                onPressed: () {
                                                                  showDialog(
                                                                    context:
                                                                        context,
                                                                    builder: (BuildContext
                                                                            context) =>
                                                                        _buildDeletePopupDialog(
                                                                            context),
                                                                  );
                                                                },
                                                              )
                                                            ],
                                                          ),
                                                          SizedBox(
                                                            height: 10,
                                                          ),
                                                        ],
                                                      )),
                                                ],
                                              ));
                                            },
                                          );
                                        } else {
                                          return Text('No Data');
                                        }
                                      }
                                      break;
                                    default:
                                      return Container();
                                      break;
                                  }
                                }),
 ],
                        ),
                      ),
                    )
                  ],
                )
            )
        )
    );

How can I implement SingleChildScrollView correctly?

在此处输入图像描述

How can I implement SingleChildScrollView correctly?

Set some height for the parent container of SingleChildScrollView . You need to give height parent container.

Can you try this code

CustomScrollView(
            scrollDirection: Axis.vertical,
            slivers: [
              SliverFillRemaining(
                hasScrollBody: false,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text('everything works'),
                    for (int i = 0; i < 10; i++) const FlutterLogo(size: 80)
                  ],
                ),
              ),
            ],
          ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM