Tags
Flutter
Asked 2 years ago
15 Oct 2021
Views 762
Everette

Everette posted

Flutter : Error - RenderBox was not laid out: RenderPointerListener#f99db relayoutBoundary=up18 NEEDS-PAINT

Flutter : Error - RenderBox was not laid out: RenderPointerListener#f99db relayoutBoundary=up18 NEEDS-PAINT

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      
        home: Scaffold(
        appBar: AppBar(
        title:Row( children:<Widget> [  TopbarSearchText()], ),
  
    ) 
    )
    );
  }
}
class TopbarSearchText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TextField(

      decoration: const InputDecoration(
          fillColor: Colors.white,filled: true,
          border: OutlineInputBorder(),
          prefixIcon: Icon(Icons.search),

          hintText: 'Enter a search term'),
    );
  }
}

i am inserting the Row with multiple children at AppBar and getting error :

The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderIgnorePointer#abaa5 relayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion:: 'hasSize'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.


denyy

denyy
answered Oct 15 '21 00:00

wrap the error causing widgets to the Expanded() widget
so in your case wrap Expanded() to the TopbarSearchText()

Expanded(child: TopbarSearchText()) 


final correct code with Expanded() widget to solve the Flutter : Error - RenderBox was not laid out: RenderPointerListener#f99db relayoutBoundary=up18 NEEDS-PAINT

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      
        home: Scaffold(
        appBar: AppBar(
        title:Row( children:<Widget> [  Expanded(child:TopbarSearchText())], ),
  
    ) 
    )
    );
  }
}
class TopbarSearchText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TextField(

      decoration: const InputDecoration(
          fillColor: Colors.white,filled: true,
          border: OutlineInputBorder(),
          prefixIcon: Icon(Icons.search),

          hintText: 'Enter a search term'),
    );
  }
}
Post Answer