3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutter ScaffoldにSingleChildScrollViewはダメ

Posted at

はじめに

スクリーンショット 2022-05-03 14.44.26.png

The following assertion was thrown during layout:
A RenderFlex overflowed by 16 pixels on the bottom.

よくあるエラーに遭遇し、「SingleChildScrollViewで囲むの忘れてた〜」くらいの気持ちで👇のように修正

@override
  Widget build(BuildContext context) {
    final UserProvider userProvider = Provider.of<UserProvider>(context);
    SizeConfig().init(context);
    return SingleChildScrollView(
      child: Scaffold(
        appBar: AppBar(
          title: Text(
            '投稿',
            style: Theme.of(context).textTheme.headline6,
          ),
          backgroundColor: primaryColor,
        ),
        body: Container(
          padding: EdgeInsets.symmetric(
            vertical: SizeConfig.blockSizeVertical! * 5,
            horizontal: SizeConfig.blockSizeHorizontal! * 5,
          ),
          child: Form(
// 以下つづく

高さが無限と言われた

The following assertion was thrown during performLayout():
RenderCustomMultiChildLayoutBox object was given an infinite size during layout.

This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
The nearest ancestor providing an unbounded height constraint is: _RenderSingleChildViewport#1d861 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
The constraints that applied to the RenderCustomMultiChildLayoutBox were: BoxConstraints(w=375.0, 0.0<=h<=Infinity)
The exact size it was given was: Size(375.0, Infinity)

See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.

The relevant error-causing widget was
Scaffold
lib/…/post/post_screen.dart:60
When the exception was thrown, this was the stack


════════ Exception caught by rendering library ═════════════════════════════════
RenderPhysicalModel object was given an infinite size during layout.
The relevant error-causing widget was
Scaffold
lib/…/post/post_screen.dart:60
════════════════════════════════════════════════════════════════════════════════

こんな感じで長文のエラーメッセージをいただきました。。。

ScaffoldにSingleChildScrollViewはダメ

めっちゃ盛大に勘違いしてました。。

SingleChildScrollViewScaffoldにやっているではありませんか:scream:

👇のように修正

@override
  Widget build(BuildContext context) {
    final UserProvider userProvider = Provider.of<UserProvider>(context);
    SizeConfig().init(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '投稿',
          style: Theme.of(context).textTheme.headline6,
        ),
        backgroundColor: primaryColor,
      ),
      // Scaffoldではなくbodyの中のContainerにSingleChildScrollViewを適応
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.symmetric(
            vertical: SizeConfig.blockSizeVertical! * 5,
            horizontal: SizeConfig.blockSizeHorizontal! * 5,
          ),
          child: Form(
            key: _form,
            child: Column(
              children: <Widget>[
// 以下つづく

勘違いしないように気をつけましょう!
Scaffoldは高さInfinityです

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?