skip to Main Content

Exception caught by rendering library
RenderBox was not laid out: RenderSemanticsGestureHandler#5a90d relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
‘package:flutter/src/rendering/box.dart’:
Failed assertion: line 1972 pos 12: ‘hasSize’
The relevant error-causing widget was:

Exception caught by gestures library
Cannot hit test a render box with no size.

double deviceHeight = MediaQuery.of(context).size.height;

return Scaffold(
  backgroundColor: const Color(0xFF101d25),
  body: Center(
    child: Container(
      height: deviceHeight,
      color: const Color(0xFF101d25),
      child: Column(
        children: [
          const Padding(
            padding: EdgeInsets.only(top: 110),
            child: Text(
              'Welcome to WhatsApp',
              style: TextStyle(
                fontSize: 35,
                color: Colors.white,
                fontWeight: FontWeight.bold,
              ),
              textAlign: TextAlign.center,
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 70, bottom: 70),
            child: Expanded(
              child: SizedBox(
                child: Image.asset(
                  'images/image_whatsapp.jpg',
                  height: 260,
                  width: 260,
                ),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 22),
            child: RichText(
              textAlign: TextAlign.center,
              text: TextSpan(children: [
                const TextSpan(
                    text: 'Read our ',
                    style: TextStyle(color: Colors.white, fontSize: 16)),
                TextSpan(
                    text: 'Privicy Police',
                    style:
                        const TextStyle(color: Colors.blue, fontSize: 16),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        // print('CLICK TAP ');
                        showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return AlertDialog(
                                title: const Text('Privicy Police'),
                                content: const Text(
                                    'This is a test to show a Alert dialog...'),
                                actions: <Widget>[
                                  TextButton(
                                    child: const Text('Agree'),
                                    onPressed: () {
                                      Navigator.of(context).pop();
                                    },
                                  ),
                                  TextButton(
                                    child: const Text('Disagree'),
                                    onPressed: () {
                                      Navigator.of(context).pop();
                                    },
                                  )
                                ],
                              );
                            });
                      }),
                const TextSpan(
                  text: ' Tap "Agree and continue" to accept the ',
                  style: TextStyle(color: Colors.white, fontSize: 16),
                ),
                TextSpan(
                    text: 'Terms of Service',
                    style:
                        const TextStyle(color: Colors.blue, fontSize: 16),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        //print('CLICK AGREE');
                        showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return AlertDialog(
                                title: const Text('Terms of Service'),
                                content: const Text(
                                    'This is a test to show a Alert dialog...'),
                                actions: <Widget>[
                                  TextButton(
                                    child: const Text('Agree'),
                                    onPressed: () {
                                      Navigator.of(context).pop();
                                    },
                                  ),
                                  TextButton(
                                    child: const Text('Disagree'),
                                    onPressed: () {
                                      Navigator.of(context).pop();
                                    },
                                  )
                                ],
                              );
                            });
                      }),
                const TextSpan(
                  text: '.',
                  style: TextStyle(color: Colors.white, fontSize: 16),
                ),
              ]),
            ),
          ),
          const SizedBox(height: 20),
          SizedBox(
            height: 50,
            width: 480,
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 50),
              child: ElevatedButton(
                  onPressed: () {
                    _dialogBuilder(context);
                    //('AGREE AND CONTINUE');
                  },
                  style: ElevatedButton.styleFrom(
                      shape: BeveledRectangleBorder(
                          borderRadius: BorderRadius.circular(2)),
                      backgroundColor: const Color(0xFF0ca886)),
                  child: const Padding(
                    padding: EdgeInsets.symmetric(vertical: 12),
                    child: Text(
                      'AGREE AND CONTINUE',
                      style: TextStyle(
                          color: Color(0xFF121a21), fontSize: 16),
                    ),
                  )),
            ),
          ),
          const Expanded(
            child: SizedBox(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Text(
                    "From",
                    style: TextStyle(color: Colors.white),
                    textAlign: TextAlign.center,
                  ),
                  Text("FACEBOOK",
                      style: TextStyle(
                        letterSpacing: 3,
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 16,
                      ),
                      textAlign: TextAlign.center)
                ],
              ),
            ),
          ),
        ],
      ),
    ),
  ),
);

}

2

Answers


  1. Chosen as BEST ANSWER

    Here's what I did, but it's still not good.

    double deviceHeight = MediaQuery.of(context).size.height;
    double deviceWidth = MediaQuery.of(context).size.width;
    
    return Scaffold(
      backgroundColor: const Color(0xFF101d25),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Padding(
              padding: EdgeInsets.only(top: deviceHeight * 0.08),
              child: Text(
                'Welcome to WhatsApp',
                style: TextStyle(
                  fontSize: deviceWidth * 0.09,
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
                textAlign: TextAlign.center,
              ),
            ),
            SizedBox(height: deviceHeight * 0.1),
            Image.asset('images/image_whatsapp.jpg',
                height: deviceWidth * 0.7, 
                width: deviceWidth * 0.7
                ),
            SizedBox(height: deviceHeight * 0.1),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: deviceWidth * 0.05),
              child: RichText(
                textAlign: TextAlign.center,
                text: TextSpan(children: [
                  TextSpan(
                      text: 'Read our ',
                      style: TextStyle(
                          color: Colors.white, fontSize: deviceWidth * 0.04)),
                  TextSpan(
                      text: 'Privicy Police',
                      style: TextStyle(
                          color: Colors.blue, fontSize: deviceWidth * 0.04),
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          // print('CLICK TAP ');
                          showDialog(
                              context: context,
                              builder: (BuildContext context) {
                                return AlertDialog(
                                  title: const Text('Privicy Police'),
                                  content: const Text(
                                      'This is a test to show a Alert dialog...'),
                                  actions: <Widget>[
                                    TextButton(
                                      child: const Text('Agree'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    ),
                                    TextButton(
                                      child: const Text('Disagree'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    )
                                  ],
                                );
                              });
                        }),
                  TextSpan(
                    text: ' Tap "Agree and continue" to accept the ',
                    style: TextStyle(
                        color: Colors.white, fontSize: deviceWidth * 0.04),
                  ),
                  TextSpan(
                      text: 'Terms of Service',
                      style: TextStyle(
                          color: Colors.blue, fontSize: deviceWidth * 0.04),
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          //print('CLICK AGREE');
                          showDialog(
                              context: context,
                              builder: (BuildContext context) {
                                return AlertDialog(
                                  title: const Text('Terms of Service'),
                                  content: const Text(
                                      'This is a test to show a Alert dialog...'),
                                  actions: <Widget>[
                                    TextButton(
                                      child: const Text('Agree'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    ),
                                    TextButton(
                                      child: const Text('Disagree'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    )
                                  ],
                                );
                              });
                        }),
                  TextSpan(
                    text: '.',
                    style: TextStyle(
                        color: Colors.white, fontSize: deviceWidth * 0.04),
                  ),
                ]),
              ),
            ),
            SizedBox(height: deviceHeight * 0.02),
            SizedBox(
              height: deviceHeight * 0.06,
              width: deviceWidth * 0.8,
              child: ElevatedButton(
                  onPressed: () {
                    _dialogBuilder(context);
                    //('AGREE AND CONTINUE');
                  },
                  style: ElevatedButton.styleFrom(
                      shape: BeveledRectangleBorder(
                          borderRadius: BorderRadius.circular(2)),
                      backgroundColor: const Color(0xFF0ca886)),
                  child: const Padding(
                    padding: EdgeInsets.symmetric(vertical: 12),
                    child: Text(
                      'AGREE AND CONTINUE',
                      style: TextStyle(color: Color(0xFF121a21), fontSize: 16),
                    ),
                  )),
            ),
            SizedBox(
              height: deviceHeight > 300 ? deviceHeight * 0.16 : deviceHeight,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  const Text(
                    "From",
                    style: TextStyle(color: Colors.white),
                    textAlign: TextAlign.center,
                  ),
                  Text("FACEBOOK",
                      style: TextStyle(
                        letterSpacing: 3,
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: deviceWidth * 0.04,
                      ),
                      textAlign: TextAlign.center),
                  //SizedBox(height: deviceHeight * 0.09)
                ],
              ),
            ),
          ],
        ),
      ),
    );
    

    }


  2. Base on the code you shared, it looks like you’ve used the Expanded widget wrongly in one of the items. Here is the corrected version below. Let me know if this solved your issue.

    import 'package:flutter/gestures.dart';
    import 'package:flutter/material.dart';
    
    main () {
      
      runApp(TestApp());
    }
    
    class TestApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        double deviceHeight = MediaQuery.of(context).size.height;
    
        return MaterialApp(
            home: Scaffold(
                backgroundColor: const Color(0xFF101d25),
                body: Center(
                  child: Container(
                    height: deviceHeight,
                    color: const Color(0xFF101d25),
                    child: Column(
                      children: [
                        const Padding(
                          padding: EdgeInsets.only(top: 110),
                          child: Text(
                            'Welcome to WhatsApp',
                            style: TextStyle(
                              fontSize: 35,
                              color: Colors.white,
                              fontWeight: FontWeight.bold,
                            ),
                            textAlign: TextAlign.center,
                          ),
                        ),
                        
                        // The change is here
                       Expanded(
                            child: Padding(
                              padding: const EdgeInsets.only(top: 70, bottom: 70),
                              child:
                              SizedBox(
                              child: Image.asset(
                                'images/image_whatsapp.jpg',
                                height: 260,
                                width: 260,
                              ),
                            ),
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 22),
                          child: RichText(
                            textAlign: TextAlign.center,
                            text: TextSpan(children: [
                              const TextSpan(
                                  text: 'Read our ',
                                  style:
                                      TextStyle(color: Colors.white, fontSize: 16)),
                              TextSpan(
                                  text: 'Privicy Police',
                                  style: const TextStyle(
                                      color: Colors.blue, fontSize: 16),
                                  recognizer: TapGestureRecognizer()
                                    ..onTap = () {
                                      // print('CLICK TAP ');
                                      showDialog(
                                          context: context,
                                          builder: (BuildContext context) {
                                            return AlertDialog(
                                              title: const Text('Privicy Police'),
                                              content: const Text(
                                                  'This is a test to show a Alert dialog...'),
                                              actions: <Widget>[
                                                TextButton(
                                                  child: const Text('Agree'),
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                ),
                                                TextButton(
                                                  child: const Text('Disagree'),
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                )
                                              ],
                                            );
                                          });
                                    }),
                              const TextSpan(
                                text: ' Tap "Agree and continue" to accept the ',
                                style: TextStyle(color: Colors.white, fontSize: 16),
                              ),
                              TextSpan(
                                  text: 'Terms of Service',
                                  style: const TextStyle(
                                      color: Colors.blue, fontSize: 16),
                                  recognizer: TapGestureRecognizer()
                                    ..onTap = () {
                                      //print('CLICK AGREE');
                                      showDialog(
                                          context: context,
                                          builder: (BuildContext context) {
                                            return AlertDialog(
                                              title: const Text('Terms of Service'),
                                              content: const Text(
                                                  'This is a test to show a Alert dialog...'),
                                              actions: <Widget>[
                                                TextButton(
                                                  child: const Text('Agree'),
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                ),
                                                TextButton(
                                                  child: const Text('Disagree'),
                                                  onPressed: () {
                                                    Navigator.of(context).pop();
                                                  },
                                                )
                                              ],
                                            );
                                          });
                                    }),
                              const TextSpan(
                                text: '.',
                                style: TextStyle(color: Colors.white, fontSize: 16),
                              ),
                            ]),
                          ),
                        ),
                        const SizedBox(height: 20),
                        SizedBox(
                          height: 50,
                          width: 480,
                          child: Padding(
                            padding: const EdgeInsets.symmetric(horizontal: 50),
                            child: ElevatedButton(
                                onPressed: () {
    //                     _dialogBuilder(context);
                                  //('AGREE AND CONTINUE');
                                },
                                style: ElevatedButton.styleFrom(
                                    shape: BeveledRectangleBorder(
                                        borderRadius: BorderRadius.circular(2)),
                                    backgroundColor: const Color(0xFF0ca886)),
                                child: const Padding(
                                  padding: EdgeInsets.symmetric(vertical: 12),
                                  child: Text(
                                    'AGREE AND CONTINUE',
                                    style: TextStyle(
                                        color: Color(0xFF121a21), fontSize: 16),
                                  ),
                                )),
                          ),
                        ),
                        const Expanded(
                          child: SizedBox(
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Text(
                                  "From",
                                  style: TextStyle(color: Colors.white),
                                  textAlign: TextAlign.center,
                                ),
                                Text("FACEBOOK",
                                    style: TextStyle(
                                      letterSpacing: 3,
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16,
                                    ),
                                    textAlign: TextAlign.center)
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                )));
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search