Skip to content

CupertinoActionSheet throws infinite size during layout error #56172

Closed

Description

@nicholastps93

I get the following error when calling the CupertinoActionSheet when implementing SingleChildScrollView on my stateful widget:

_RenderCupertinoAlertActions object was given an infinite size during layout.
The relevant error-causing widget was
CupertinoActionSheet
lib\main.dart:82
The following RenderObject was being processed when the exception was fired: _RenderCupertinoAlertActions#56898 relayoutBoundary=up19 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: _RenderCupertinoAlertActions#56898 relayoutBoundary=up19 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
constraints: BoxConstraints(w=395.4, 0.0<=h<=Infinity)
size: Size(395.4, Infinity)
child 1: RenderPointerListener#7df6e relayoutBoundary=up20 NEEDS-PAINT
parentData: offset=Offset(0.0, 0.0); id=null (can use size)
constraints: BoxConstraints(w=395.4, 0.0<=h<=Infinity)
size: Size(395.4, Infinity)
behavior: opaque
listeners: down

The full code is attached here:

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {

List leaveTypes = ["Vacation Leave","Ordinary Sick Leave","Childcare Leave"];
String applyLeaveType;

@OverRide
Widget build(BuildContext context) {
if(applyLeaveType == null){
applyLeaveType = leaveTypes[0];
};
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: LayoutBuilder(builder:(context, constraints){
return SingleChildScrollView(
/child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: constraints.maxWidth, minHeight: constraints.maxHeight
),
/
child: Container(
height: constraints.maxHeight,
color: Color.fromARGB(255, 244, 246, 249),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Text for leave type
Container(
alignment: Alignment(-1.0,0.0),
padding:EdgeInsets.only(
top: 10, bottom: 5, left: 20, right: 20
),
child: Text("I want to apply for",
style: TextStyle(fontSize: 16),
textAlign: TextAlign.left,
)
),
SizedBox(
width: MediaQuery.of(context).size.width,
height:80,
child: GestureDetector(
onTap:() {
final action = Container(
height: MediaQuery.of(context).size.height,
child: CupertinoActionSheet(

                        title: Text(
                          "Leave Type",
                          style: TextStyle(fontSize:16)
                        ),
                        actions: leaveTypes.map((leaveType){
                          CupertinoActionSheetAction(
                            child:Text(leaveType),
                            onPressed:(){
                              setState((){
                                applyLeaveType=leaveType;
                              });
                              Navigator.pop(context);
                            }
                          );
                        }).toList(),
                        cancelButton: CupertinoActionSheetAction(
                          child: Text("Back"),
                          onPressed:(){
                            Navigator.pop(context);
                          }
                        )
                      )
                    );
                    showCupertinoModalPopup(context: context, builder: (context) => action);
                  },
                  child: Container(
                    alignment: Alignment(0.0,0.0),
                    padding:EdgeInsets.only(
                      top: 10, bottom: 10, left: 20, right: 20
                    ),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      //border: Border.all(),
                      //borderRadius: BorderRadius.all(Radius.circular(10))
                    ),                     
                    child:Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.all(10),
                          child: Text(applyLeaveType),
                        ),
                        Container(
                          padding: EdgeInsets.all(10),
                          child: Icon(Icons.keyboard_arrow_down)
                        )
                      ],
                    )
                  )
                ),
              )
            ]
          )
        )
      //)
    );

  })

);

}
}

Activity

  1. nicholastps93 commented on May 4, 2020

    @nicholastps93
    Author

    I revised the GestureDetector accordingly to fix the error:

    child: GestureDetector(
    onTap:() {
    buildLeaveList(){
    List widgets = List();
    leaveTypes.forEach((leaveType){
    print(leaveType);
    widgets.add(
    CupertinoActionSheetAction(
    child: Text(leaveType),
    onPressed: () {
    setState(() {
    applyLeaveType = leaveType;
    });
    Navigator.pop(context);
    }
    )
    );
    return widgets;
    });
    }
    final action = Container(
    height: MediaQuery.of(context).size.height,
    child: CupertinoActionSheet(

                            title: Text(
                              "Leave Type",
                              style: TextStyle(fontSize:16)
                            ),
                            actions: buildLeaveList(),
                            cancelButton: CupertinoActionSheetAction(
                              child: Text("Back"),
                              onPressed:(){
                                Navigator.pop(context);
                              }
                            )
                          )
                        );
                        showCupertinoModalPopup(context: context, builder: (context) => action);
                      }
    

    But now none of the actionsheet is being displayed (no options when opening the modal).

  2. TahaTesser commented on May 4, 2020

    @TahaTesser
    Contributor

    Hi @nicholastps93
    This looks like an an issue with your code and not CupertinoActionSheet sheet

    Working code sample

    Code Sample
    import 'package:flutter/material.dart';
    import 'package:flutter/cupertino.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
    // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State {
      List leaveTypes = [
        "Vacation Leave",
        "Ordinary Sick Leave",
        "Childcare Leave"
      ];
      String applyLeaveType;
    
      @override
      Widget build(BuildContext context) {
        if (applyLeaveType == null) {
          applyLeaveType = leaveTypes[0];
        }
        ;
        return Scaffold(
            appBar: AppBar(
              title: Text('App'),
            ),
            body: LayoutBuilder(builder: (context, constraints) {
              return SingleChildScrollView(
                  child: ConstrainedBox(
                      constraints: BoxConstraints(
                          minWidth: constraints.maxWidth,
                          minHeight: constraints.maxHeight),
                      child: Container(
                          height: constraints.maxHeight,
                          color: Color.fromARGB(255, 244, 246, 249),
                          child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
    //Text for leave type
                                Container(
                                    alignment: Alignment(-1.0, 0.0),
                                    padding: EdgeInsets.only(
                                        top: 10, bottom: 5, left: 20, right: 20),
                                    child: Text(
                                      "I want to apply for",
                                      style: TextStyle(fontSize: 16),
                                      textAlign: TextAlign.left,
                                    )),
                                SizedBox(
                                  width: MediaQuery.of(context).size.width,
                                  height: 80,
                                  child: GestureDetector(
                                      onTap: () => _handleClickMe(context),
                                      child: Container(
                                          alignment: Alignment(0.0, 0.0),
                                          padding: EdgeInsets.only(
                                              top: 10,
                                              bottom: 10,
                                              left: 20,
                                              right: 20),
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            //border: Border.all(),
                                            //borderRadius: BorderRadius.all(Radius.circular(10))
                                          ),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Container(
                                                padding: EdgeInsets.all(10),
                                                child: Text(applyLeaveType),
                                              ),
                                              Container(
                                                  padding: EdgeInsets.all(10),
                                                  child: Icon(
                                                      Icons.keyboard_arrow_down))
                                            ],
                                          ))),
                                )
                              ]))
                      //)
                      ));
            }));
      }
    
      Future<void> _handleClickMe(BuildContext context) async {
        return showCupertinoModalPopup<void>(
          context: context,
          builder: (BuildContext context) {
            return CupertinoActionSheet(
              title: Text('Favorite Dessert'),
              message:
                  Text('Please select the best dessert from the options below.'),
              actions: <Widget>[
                CupertinoActionSheetAction(
                  child: Text('Profiteroles'),
                  onPressed: () {/** */},
                ),
                CupertinoActionSheetAction(
                  child: Text('Cannolis'),
                  onPressed: () {/** */},
                ),
                CupertinoActionSheetAction(
                  child: Text('Trifie'),
                  onPressed: () {/** */},
                ),
              ],
              cancelButton: CupertinoActionSheetAction(
                isDefaultAction: true,
                child: Text('Cancel'),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
            );
          },
        );
      }
    }
    
    

    This platform is not meant for assistance on personal code.
    Please see https://flutter.dev/community for resources and asking questions like this, you may also get some help if you post it on Stack Overflow.
    Closing, as this isn't an issue with Flutter itself,
    if you disagree please write in the comments and I will reopen it
    Thank you

  3. lock commented on May 21, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked and limited conversation to collaborators on May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions