thefutter底部被xx像素溢出

发布于 2025-02-06 06:10:46 字数 3143 浏览 2 评论 0原文

我正在尝试构建一个带有多个小部件行,列,扩展,列表视图等的页面...

我有点困惑。我想要一个可以用小部件滚动的页面themelist。 我有错误:

底部的28像素溢出的renderflex。

class SettingsViewState extends State<SettingsView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      drawer: const NavDrawer(),
      appBar: AppBar(
        title: Text(AppLocalizations.of(context)!.settingsTitle),
        backgroundColor: Theme.of(context).primaryColor,
      ),
      body: CustomScrollView(slivers: [
        SliverFillRemaining(
          child: Column(
            children: const [
              ThemeList(),
              SizedBox(height: 8),
              ThemeList(),
              SizedBox(height: 8),
              ThemeList(),
            ],
          ),
        ),
      ]),
    );
  }
}

class ThemeList extends StatelessWidget {
  const ThemeList({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Padding(
        padding: const EdgeInsets.all(10),
        child: Container(
          decoration: BoxDecoration(
            border: Border.all(color: Theme.of(context).primaryColor, width: 2),
            borderRadius: BorderRadius.circular(10),
          ),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(top: 5, left: 20),
                    child: Text(
                      AppLocalizations.of(context)!.settingsThemeSubTitle,
                      style: const TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 23,
                      ),
                    ),
                  )
                ],
              ),
              ListView.builder(
                shrinkWrap: true,
                padding: const EdgeInsets.all(8),
                itemCount: AppTheme.values.length,
                itemBuilder: (context, index) {
                  final itemAppTheme = AppTheme.values[index];
                  var nameTheme = itemAppTheme.toString()
                  return Card(
                    color: appThemeData[itemAppTheme]?.primaryColor,
                    child: ListTile(
                      title: Text(
                        nameTheme,
                        style: appThemeData[itemAppTheme]?.textTheme.bodyText1,
                      ),
                      onTap: () {
                        BlocProvider.of<ThemeBloc>(context).add(
                          ThemeChanged(theme: itemAppTheme),
                        );
                        Preferences.saveTheme(itemAppTheme);
                      },
                    ),
                  );
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

所需结果:

“在此处输入图像描述”

I am trying to construct a page with multiple widgets Row, Column, Expanded, ListView, etc...

I am a bit confused. I want a page scrollable with my widgets ThemeList.
I have the error :

A RenderFlex overflowed by 28 pixels on the bottom.

class SettingsViewState extends State<SettingsView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      drawer: const NavDrawer(),
      appBar: AppBar(
        title: Text(AppLocalizations.of(context)!.settingsTitle),
        backgroundColor: Theme.of(context).primaryColor,
      ),
      body: CustomScrollView(slivers: [
        SliverFillRemaining(
          child: Column(
            children: const [
              ThemeList(),
              SizedBox(height: 8),
              ThemeList(),
              SizedBox(height: 8),
              ThemeList(),
            ],
          ),
        ),
      ]),
    );
  }
}

class ThemeList extends StatelessWidget {
  const ThemeList({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Padding(
        padding: const EdgeInsets.all(10),
        child: Container(
          decoration: BoxDecoration(
            border: Border.all(color: Theme.of(context).primaryColor, width: 2),
            borderRadius: BorderRadius.circular(10),
          ),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(top: 5, left: 20),
                    child: Text(
                      AppLocalizations.of(context)!.settingsThemeSubTitle,
                      style: const TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 23,
                      ),
                    ),
                  )
                ],
              ),
              ListView.builder(
                shrinkWrap: true,
                padding: const EdgeInsets.all(8),
                itemCount: AppTheme.values.length,
                itemBuilder: (context, index) {
                  final itemAppTheme = AppTheme.values[index];
                  var nameTheme = itemAppTheme.toString()
                  return Card(
                    color: appThemeData[itemAppTheme]?.primaryColor,
                    child: ListTile(
                      title: Text(
                        nameTheme,
                        style: appThemeData[itemAppTheme]?.textTheme.bodyText1,
                      ),
                      onTap: () {
                        BlocProvider.of<ThemeBloc>(context).add(
                          ThemeChanged(theme: itemAppTheme),
                        );
                        Preferences.saveTheme(itemAppTheme);
                      },
                    ),
                  );
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

Desired result :

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫尐诺 2025-02-13 06:10:46

只需用themelist将内部包装listView.builder()用展开,问题就会消失。


如果您想在每个themelist中都使用滚动显示整个屏幕中的所有

  1. 项目脚手架 be singlechildscrollview作为其孩子。
  2. themelist的开始时删除扩展的
  3. 删除listView.builder()themelist中,并用任何循环逻辑替换以直接渲染卡片,例如:
...AppTheme.values.map((itemAppTheme) {
  var nameTheme = itemAppTheme.toString();
  return Card(
    color: appThemeData[itemAppTheme]?.primaryColor,
    child: ListTile(
      title: Text(
        nameTheme,
        style: appThemeData[itemAppTheme]?.textTheme.bodyText1,
      ),
      onTap: () {
        BlocProvider.of<ThemeBloc>(context).add(
          ThemeChanged(theme: itemAppTheme),
        );
        Preferences.saveTheme(itemAppTheme);
      },
    ),
  );
}).toList()

Just wrap the ListView.builder() inside ThemeList with an Expanded and the problem would vanish.


If you want to have all the items inside each ThemeList displayed with a scroll for the whole screen then the easiest why is to do the following:

  1. Change the CustomScrollView in the body of the Scaffold to be SingleChildScrollView with the Column as its child.
  2. Remove the Expanded at the start of ThemeList.
  3. Remove the ListView.builder() inside the ThemeList and replace it with any looping logic to directly render the cards, for example:
...AppTheme.values.map((itemAppTheme) {
  var nameTheme = itemAppTheme.toString();
  return Card(
    color: appThemeData[itemAppTheme]?.primaryColor,
    child: ListTile(
      title: Text(
        nameTheme,
        style: appThemeData[itemAppTheme]?.textTheme.bodyText1,
      ),
      onTap: () {
        BlocProvider.of<ThemeBloc>(context).add(
          ThemeChanged(theme: itemAppTheme),
        );
        Preferences.saveTheme(itemAppTheme);
      },
    ),
  );
}).toList()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文