Play Flutter Quiz. Click here .

Error: Incorrect use of ParentDataWidget.

This Errors is posted by seven.srikanth@gmail.com at 07-12-2018 18:28:25



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.
Explanation
This error means that you can only place an Expanded Widget inside Flex Widget. For example, below code will throw this kind of error.
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: <Widget>[
Column(
children: <Widget>[
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: 'My Layout App',
home: Scaffold(
appBar: AppBar(
title: Text("My Layout App"),
),
body: ListView(
children: <Widget>[
titlesection,
],
)),
);
}
}
The fix for this above issue, is to move the expanded widget inside a flex widget. Example below.
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: Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
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: 'My Layout App',
home: Scaffold(
appBar: AppBar(
title: Text("My Layout App"),
),
body: ListView(
children: <Widget>[
titlesection,
],
)),
);
}
}

Tags: Incorrect use of ParentDataWidget.




0 Comments
Login to comment.

Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.







© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com

Terms | Privacy