首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何解决嵌套ListView.builder的问题?

如何解决嵌套ListView.builder的问题?
EN

Stack Overflow用户
提问于 2022-06-28 09:10:30
回答 1查看 139关注 0票数 0

我在开发一个颤振应用程序。我在小部件树中放置一个ListView.builder时遇到了错误。

根据不同的小部件,我收到了一些错误。然而,它们都指出了相同的问题:Failed assertion: line 1979 pos 12: 'hasSize

代码语言:javascript
运行
复制
The last error I have received:
======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
RenderBox was not laid out: RenderRepaintBoundary#bc86b relayoutBoundary=up5 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1979 pos 12: 'hasSize'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was: 
  Column Column:file:///Users/julianmodlinski/StudioProjects/caralgo_mobile_app/lib/widgets/map_page.dart:137:22

代码结构如下:

代码语言:javascript
运行
复制
MainPage.dart
Scaffold(
      body: SafeArea(
        child: _pages.elementAt(_selectedIndex),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: ImageIcon(
                AssetImage('assets/images/informations_logo.png'),
                size: 40,
              ),
              label: 'Informations'
          ),
          BottomNavigationBarItem(
              icon: ImageIcon(
                AssetImage('assets/images/localisation_logo.png'),
                size: 40,
              ),
              label: 'Localisation'
          ),
          BottomNavigationBarItem(
              icon: ImageIcon(
                AssetImage('assets/images/new_button.png'),
                size: 70,
                color: Constants.colorOrange,
              ),
              label: 'Add new info card'
          ),
          BottomNavigationBarItem(
              icon: ImageIcon(
                AssetImage('assets/images/reservations_logo.png'),
                size: 40,
              ),
              label: 'Reservations'
          ),
          BottomNavigationBarItem(
              icon: ImageIcon(
                AssetImage('assets/images/profile_logo.png'),
                size: 40,
              ),
              label: 'Profile'
          ),
        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          if(_bleDeviceProvider.bluetoothDeviceState == BluetoothDeviceState.connected){
            _bleDeviceProvider.getLoRaMessages(_user);
          }
        },
      ),
    );

MapPage.dart
Stack(
      alignment: Alignment.center,
      children: [
        buildColumn(context),
        Visibility(
          visible: _chosenVehiclePosition != null,
          child: Align(
            alignment: Alignment.bottomCenter,
            child: Padding(
                padding: const EdgeInsets.fromLTRB(0, 0, 0, 30),
                child: ElevatedButton(
                    child: Text(S.of(context).navigateToVehicle),
                    onPressed: () async {
                      String googleUrl = 'https://www.google.com/maps/search/?api=1&query=${_chosenVehiclePosition.latitude.toString()},${_chosenVehiclePosition.longitude.toString()}';
                      if (await canLaunch(googleUrl)) {
                        await launch(googleUrl);
                      } else {
                        throw 'Could not open the map.';
                      }
                    })
            ),
          ),
        )
      ],
    );

buildColumn()
Column(
        children: [
          const Text(
            "Localisations",
            style: TextStyle(
                fontSize: 36,
                fontWeight: FontWeight.w400,
                fontFamily: "Comfortaa"
            ),
          ),
          const SizedBox(height: 5),
          Flexible(
            child: FutureBuilder(
                future: getVehiclesPosition(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if(snapshot.hasData){
                    return GoogleMap(
                      myLocationEnabled: true,
                      mapToolbarEnabled: false,
                      onMapCreated: _onMapCreated,
                      initialCameraPosition: CameraPosition(
                          target: _initialPosition,
                          zoom: 11.0
                      ),
                      markers: snapshot.data.values.toSet(),
                    );
                  } else {
                    return const Center(
                      child: SizedBox(
                        width: 60,
                        height: 60,
                        child: CircularProgressIndicator(),
                      ),
                    );
                  }
                }
            ),
          ),
          Flexible(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 4),
                    child: Text(
                      S.of(context).vehicles,
                      style: const TextStyle(
                        fontSize: 17,
                        fontWeight: FontWeight.w400,
                        fontFamily: "Comfortaa"
                      ),
                    ),
                  ),
                  const Divider(),
                  ListView.builder(
                    shrinkWrap: true,
                    itemCount: _user.vehicles!.length,
                    itemBuilder: (BuildContext context, int index) {
                      return VehicleTab(vehicle: _user.vehicles![index]);
                    },
                  ),
                ],
              )
          )
        ],
      );
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-28 09:36:03

ListView.builder小部件放入Expanded小部件中

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72783701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档