【问题标题】:How to Make column scrollable with keeping Expanded Widgets flutter?如何在保持扩展小部件颤动的情况下使列可滚动?
【发布时间】:2021-04-06 10:24:52
【问题描述】:

大家好,我正在尝试将 Column 转换为可滚动我尝试在 SingleChildScrollView 中扭曲 Column(删除所有展开的小部件)但我收到错误我将列转换为 ListView(删除所有展开的小部件)但我得到一个错误。

有没有办法保留展开的小部件?

那么有人可以帮助我吗?请

这是我的代码

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      floatingActionButton: buttonTheme,
      drawer: SideMenu(),
      appBar: AppBar(
        actions: [
          Padding(
            padding: EdgeInsets.all(8.0),
            child: DropdownButton(
              underline: SizedBox(),
              icon: Icon(
                Icons.language,
                color: Colors.white,
              ),
              items: AppLanguage.languageList()
                  .map<DropdownMenuItem<AppLanguage>>(
                    (lang) => DropdownMenuItem(
                      value: lang,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [Text(lang.flag), Text(lang.name)],
                      ),
                    ),
                  )
                  .toList(),
              onChanged: (AppLanguage language) {
                _changeLanguage(language);
              },
            ),
          )
        ],
        centerTitle: true,
        //automaticallyImplyLeading: false,
        title: Text(
          getTranslation(context, 'main_app_bar'),
          style: TextStyle(
            fontSize: 20,
          ),
        ),
      ),
      body: Center(
        child: SafeArea(
          child: Column(
            children: <Widget>[
              Expanded(
                flex: 1,
                child: WeatherWidget(
                  deglaPalmsWeatherData: widget.deglaPalmsWeather,
                ),
              ),
              Expanded(
                flex: 1,
                child: Column(
                  children: [
                    Expanded(
                      flex: 2,
                      child: Row(
                        children: [
                          SizedBox(
                            width: 20,
                          ),
                          Expanded(
                            flex: 1,
                            child: MapWidget(),
                          ),
                          SizedBox(
                            width: 10,
                          ),
                          Expanded(
                            flex: 1,
                            child: ServicesWidget(),
                          ),
                          SizedBox(
                            width: 20,
                          )
                        ],
                      ),
                    ),
                    Expanded(
                      flex: 2,
                      child: Row(
                        children: [
                          SizedBox(
                            width: 20,
                          ),
                          Expanded(
                            flex: 1,
                            child: InfoWidget(),
                          ),
                          SizedBox(
                            width: 10,
                          ),
                          Expanded(
                            flex: 1,
                            child: BusWidget(),
                          ),
                          SizedBox(
                            width: 20,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: SoonWidget(),
                    ),
                  ],
                ),
              ),
              DCCopyRights(),
            ],
          ),
        ),
      ),
      bottomNavigationBar: Container(
        height: bannerHeight,
      ),
    );
  }

【问题讨论】:

  • 尝试用Expanded包裹你的专栏
  • @FahmiSawalha 使用哪个小部件 SingleChildScrollView 或 ListView ?
  • 我认为你应该使用 singleChildScrollView
  • @FahmiSawalha 不工作我收到此错误Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets. The offending Expanded is currently placed inside a _SingleChildViewport widget.

标签: flutter dart


【解决方案1】:

我找到了一个解决方案,它对我来说效果很好,我使用了 PageView 和 scrollDirection 和 pageSnapping

PageView(
         scrollDirection: Axis.vertical,
         pageSnapping: false,
         children: [Column(),
                    Column()])

我必须调整小部件以适应所有屏幕,但它对我来说效果很好,因为我添加了很多小部件,现在它看起来像一个可滚动的列。 我知道这不是最好的解决方案,但它做了我想要的。

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2016-07-09
    • 2016-11-12
    • 2019-05-23
    • 2016-05-17
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    相关资源
    最近更新 更多