Reputation: 1025
I have implemented app to read captured image text using Firebase ML kit,In my screen I have display the captured image and place a button bellow the image to read the image and display extract text below the button, but when I have click the button I got following exception,
"Each child must be laid out exactly once",
I have used Huawei GR5 Mini to test the app,
My code is,
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: Text(
'Read PDF',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.lightBlue),
),
elevation: 0.0,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(color: Colors.blue),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: Container(
height: 300,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0, left: 40.0, right: 40.0, bottom: 20.0),
child: Image.file(File(widget.imageRoute), fit: BoxFit.cover),
),
),
),
),
SizedBox(
height: 10,
),
Center(
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.blue)),
color: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(10.0),
onPressed: () async {
pickImage();
},
child: Text(
"Read".toUpperCase(),
style: TextStyle(fontSize: 12.0, fontWeight: FontWeight.bold),
),
),
),
SizedBox(
height: 10,
),
Center(
child: text == ''
? Text('Text will display here')
: Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: SelectableText(
text,
),
),
),
),
),
],
),
);
}
Upvotes: 0
Views: 3302
Reputation: 63
I solve the same issue, although the above solution is correct but it seems to fail sometimes. try this command in terminal in android studio.
1. flutter clean
2. flutter run
Upvotes: 0
Reputation: 494
You use expended in center widget. You can use like this:
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: Text(
'Read PDF',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.lightBlue),
),
elevation: 0.0,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(color: Colors.blue),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 300,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0, left: 40.0, right: 40.0, bottom: 20.0),
child: Image.network("https://i1.wp.com/www.muratoner.net/wp-content/uploads/2019/01/flutterlogo.png?fit=800%2C800&ssl=1", fit: BoxFit.cover),
),
),
),
SizedBox(
height: 10,
),
Center(
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.blue)),
color: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(10.0),
onPressed: () async {
text = "Response text";
setState(() {
});
// pickImage();
},
child: Text(
"Read".toUpperCase(),
style: TextStyle(fontSize: 12.0, fontWeight: FontWeight.bold),
),
),
),
SizedBox(
height: 10,
),
text == ''
? Text('Text will display here',textAlign: TextAlign.center,)
: Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: SelectableText(
text,
),
),
),
),
],
),
);
}
Upvotes: 3