Error: Incorrect use of ParentDataWidget.

This Errors is posted by seven.srikanth at 12/7/2018 6:28:25 PM



<p>Error:Incorrect use of ParentDataWidget. Expanded widgets must be placed inside Flex widgets. Expanded(no depth, flex: 1, dirty) has no flex ancestor at all.</p> <p>Explanation This error means that you can only place an Expandedfont-size: 1rem;]( Widget inside Flex Widget. For example, below code will throw this kind of error.</p> <pre>font-size: 1rem;](

import 'package:flutter/material.dart';

void main() { runApp(MyApp()); }

class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { Widget titlesection = Container( padding: EdgeInsets.all(10.0), child: Expanded( child: Row( children: [ Column( children: [ Container( padding: EdgeInsets.only(bottom: 8.0), child: Text( "Some Lage Somthing", style: TextStyle(fontWeight: FontWeight.bold), ), ), Text("Someplace, Country") ], ), Icon(Icons.star) ], ), ), );

return MaterialApp(
  title: &#39;My Layout App&#39;,
  home: Scaffold(
      appBar: AppBar(
        title: Text(&quot;My Layout App&quot;),
      ),
      body: ListView(
        children: [
          titlesection,
        ],
      )),
);

} } </pre> <p>The fix for this above issue, is to move the expanded widget inside a flex widget. Example below.</p> <pre>import 'package:flutter/material.dart'; </pre> <p>void main() { runApp(MyApp()); }</p> <p>class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { Widget titlesection = Container( padding: EdgeInsets.all(10.0), child: Row( children: [ Expanded( child: Column( children: [ Container( padding: EdgeInsets.only(bottom: 8.0), child: Text( "Some Lage Somthing", style: TextStyle(fontWeight: FontWeight.bold), ), ), Text("Someplace, Country") ], ), ), Icon(Icons.star) ], ), );</p> <pre>return MaterialApp( title: 'My Layout App', home: Scaffold( appBar: AppBar( title: Text("My Layout App"), ), body: ListView( children: [ titlesection, ], )), ); </pre> <p>} }</p>


Tags: Incorrect use of ParentDataWidget.








0 Comments
Login to comment.
Recent Comments