Reputation: 2327
So i am trying to create a screen,i made half way through but whenever i try to add textfield with in row ,i made to do half way with overlapping images but when i try to run it it throws error like this,it happen when i try to add textfield
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.
This happens when the parent widget does not provide a finite width constraint. For example, if the InputDecorator is contained by a Row, then its width must be constrained. An Expanded widget or a SizedBox can be used to constrain the width of the InputDecorator or the TextField that contains it.
'package:flutter/src/material/input_decorator.dart':
Failed assertion: line 926 pos 7: 'layoutConstraints.maxWidth < double.infinity'
Code for Design
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Registration", style: TextStyle(color: Colors.black)),
backgroundColor: Colors.orange,
),
body: SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
child: Image.asset('assets/images/gym.png',
height: 150, width: double.infinity, fit: BoxFit.fitWidth),
),
Padding(
padding: EdgeInsets.only(top: 90, left: 20),
child: CircleAvatar(
backgroundImage: AssetImage("assets/images/user_avatar.png"),
radius: 55.0,
),
),
Row(
children: <Widget>[
TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'USer'),
),
TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Mo'),
),
],
)
],
),
),
);
}
Upvotes: 0
Views: 161
Reputation: 27217
This is happening because TextField requires Width of whole screen, to avoid it you can wrap it inside Expanded widget.
SingleChildScrollView(
child: Stack(
children: [
Column(
children: [
Container(
child: Image.asset('assets/images/crown.png',
height: 150,
width: double.infinity,
fit: BoxFit.fitWidth),
),
SizedBox(
height: 50,
),
Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none, hintText: 'USer'),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none, hintText: 'Mo'),
),
),
],
),
],
),
Padding(
padding: EdgeInsets.only(top: 90, left: 20),
child: CircleAvatar(
backgroundImage: AssetImage("assets/images/crown.png"),
radius: 55.0,
),
),
],
),
),
Upvotes: 2