Can we apply rounded borders to SliverAppBar in Flutter? - flutter

[I want to implement this UI with rounded appbar to my shop app] (https://i.stack.imgur.com/YoIIR.jpg)
When I use ClipRRect to apply rounded borders to SliverAppBars I get this error. However, I can apply ClipRRect to normal appBar. I need a sliverAppBar to hide title and only display my tabs when scroll up to save space on screen.
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#782cb](state: RawGestureDetectorState#5a576(gestures: <none>, behavior: opaque)):
A RenderNestedScrollViewViewport expected a child of type RenderSliver but received a child of type RenderClipRRect.
RenderObjects expect specific types of children because they coordinate with their children during layout and paint. For example, a RenderSliver cannot be the child of a RenderBox because a RenderSliver does not understand the RenderBox layout protocol.
The RenderNestedScrollViewViewport that expected a RenderSliver child was created by: NestedScrollViewViewport ← IgnorePointer-[GlobalKey#845ec] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#782cb] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#9de96] ← NotificationListener<ScrollMetricsNotification> ← Transform ← ClipRect ← ⋯
The RenderClipRRect that did not match the expected child type was created by: ClipRRect ← NestedScrollViewViewport ← IgnorePointer-[GlobalKey#845ec] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#782cb] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#9de96] ← NotificationListener<ScrollMetricsNotification> ← Transform ← ⋯
The relevant error-causing widget was
NestedScrollView
lib\…\screens\news_feed.dart:27
When the exception was thrown, this was the stack
Here is my code.
class NewsFeed extends StatelessWidget {
const NewsFeed({Key? key}) : super(key: key);
static const List<Widget> screens = [
RetailsScreen(),
ElonsScreen(),
RentalsScreen(),
];
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
initialIndex: 0,
child: Scaffold(
backgroundColor: AppColors.semiWhiteBackground,
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
ClipRRect(
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25),
),
child: SliverAppBar(
title: const LocaleText('newsFeed'),
pinned: true,
floating: true,
forceElevated: innerBoxIsScrolled,
bottom: const TabBar(
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 5,
indicatorColor: AppColors.secondary,
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 15,
),
tabs: [
Tab(
child: LocaleText(
'buyAndSell',
style: TextStyle(color: Colors.white),
),
),
Tab(
child: LocaleText(
'elons',
style: TextStyle(color: Colors.white),
),
),
Tab(
child: LocaleText(
'rental',
style: TextStyle(color: Colors.white),
),
),
],
),
),
),
];
},
body: const TabBarView(
children: screens,
),
),
),
);
}
}
I use a SliverAppBar to be able to hide scrollBar part of the appBar when scrolling up.

Please update your code with :
Remove the ClipRRect from the sliverAppBar and use shape property of sliverAppBar
shape: const ContinuousRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(60),
bottomRight: Radius.circular(60))),
Full code :
NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverAppBar(
title: const Text('newsFeed'),
pinned: true,
floating: true,
shape: const ContinuousRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(60),
bottomRight: Radius.circular(60))),
forceElevated: innerBoxIsScrolled,
bottom: const TabBar(
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 5,
indicatorColor: Colors.yellow,
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 15,
),
tabs: [
Tab(
child: Text(
'buyAndSell',
style: TextStyle(color: Colors.white),
),
),
Tab(
child: Text(
'elons',
style: TextStyle(color: Colors.white),
),
),
Tab(
child: Text(
'rental',
style: TextStyle(color: Colors.white),
),
),
],
),
),
];
},
body: Container(),
),

Related

How do I create a tab bar at the center of the screen?

I tried to call up the summary page but everything disappear when I put expanded:
════════ Exception caught by rendering library
═════════════════════════════════ Null check operator used on a null
value The relevant error-causing widget was Column
lib\screens\consult_profile.dart:28
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library
═════════════════════════════════ Updated layout information required
for RenderRepaintBoundary#d8a53 NEEDS-LAYOUT NEEDS-PAINT to calculate
semantics. 'package:flutter/src/rendering/object.dart': Failed
assertion: line 2647 pos 12: '!_needsLayout'
The source code is:
class MyCoolPage extends StatefulWidget {
#override
State<MyCoolPage> createState() => _MyCoolPageState();
}
class _MyCoolPageState extends State<MyCoolPage>
with SingleTickerProviderStateMixin {
TabController _tabController;
#override
void initState() {
_tabController = TabController(
length: 2,
vsync: this,
);
super.initState();
}
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: SizedBox(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 500,
height: 50,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(25),
),
child: AppBar(
bottom: TabBar(
controller: _tabController,
tabs: [
Text(
"Summary",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
Text(
"Reservations",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
],
indicator: BoxDecoration(
color: b,
borderRadius: BorderRadius.circular(25),
),
labelColor: Colors.white,
unselectedLabelColor: Colors.black,
),
),
),
// create widgets for each tab bar here
Expanded(
child: TabBarView(
controller: _tabController,
children: [
// first tab bar view widget
Container(
child: Center(
child: MyLovelySummary(),
),
),
// second tab bar view widget
Container(
child: Center(
child: MyLovelyReservations(),
),
),
],
),
),
],
),
),
);
}
}

How to solve "Incorrect use of ParentDataWidget." in main.dart

I have main.dart as below:
//main.dart
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'src/loginPage.dart';
import 'src/tabsPage.dart';
void main() async {
Widget _defaultPage = new LoginPage();
runApp(MyApp(defaultPage: _defaultPage));
}
class MyApp extends StatelessWidget {
final Widget defaultPage;
const MyApp({Key key, #required this.defaultPage}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Gaia',
debugShowCheckedModeBanner: false,
home: defaultPage,
routes: <String, WidgetBuilder>{
'/tabs': (BuildContext context) => new TabsPage(),
'/login': (BuildContext context) => new LoginPage(),
},
);
}
}
//LoginPage.dart
import 'package:flutter/material.dart';
import '../main.dart';
class LoginPage extends StatefulWidget {
#override
State<StatefulWidget> createState() => new _State();
}
class _State extends State<LoginPage> {
TextEditingController userIdController = TextEditingController();
TextEditingController passwordController = TextEditingController();
void login() async {
Navigator.of(context).pushReplacementNamed('/tabs');
}
void forgotPassword() {
print("Forgot password!");
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(40),
child: Text(
'Gaia',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 30),
)),
Container(
padding: EdgeInsets.all(10),
child: TextField(
style: TextStyle(fontSize: 25),
maxLength: 6,
keyboardType: TextInputType.number,
controller: userIdController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Id',
labelStyle: TextStyle(fontSize: 25),
counter: Spacer(),
),
),
),
Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextField(
style: TextStyle(fontSize: 25),
obscureText: true,
controller: passwordController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'password',
labelStyle: TextStyle(fontSize: 25)),
),
),
SizedBox(height: 50),
Container(
padding: EdgeInsets.fromLTRB(100, 30, 100, 0),
child: RaisedButton(
child: Text(
'ログイン',
style: TextStyle(fontSize: 30),
),
textColor: Colors.white,
color: Colors.blue,
onPressed: () {
login();
})),
SizedBox(height: 120),
FlatButton(
child: Text('Forgot password'),
onPressed: () {
forgotPassword();
},
textColor: Colors.blue,
),
Container(
alignment: Alignment.center,
child: Text('Information'),
),
Container(
alignment: Alignment.center,
child: Text('Here'),
),
],
)));
}
}
when I run it that show me warning message, what can I solve it?
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a _Decorator widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
SizedBox.shrink ← Expanded ← Spacer ← _Decorator ← InputDecorator ← AnimatedBuilder ← _PointerListener ← Listener ← RawGestureDetector ← TextSelectionGestureDetector ← ⋯
When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure>
package:flutter/…/widgets/framework.dart:5770
#1 RenderObjectElement._updateParentData
package:flutter/…/widgets/framework.dart:5786
#2 RenderObjectElement.attachRenderObject
package:flutter/…/widgets/framework.dart:5808
#3 RenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5501
#4 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:6117
...

Use build function inside AppBar

I am trying to fit in a search bar build function instead of title.
It works perfectly fine as part of the appBar body.
Here is the implementation of buildSearchBar which I want to fit inside the AppBar:
buildSearchBar(BuildContext context) {
return SliverPadding(
padding: EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
sliver: SliverList(
delegate: SliverChildListDelegate([
Card(
color: Colors.transparent,
elevation: 8,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.0)),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
color: Theme.of(context).accentColor,
child: TextField(
decoration: InputDecoration(
icon: Icon(Icons.search),
border: InputBorder.none,
hintStyle:
TextStyle(fontSize: 18, color: Colors.black54),
hintText: 'Search news'),
textInputAction: TextInputAction.search,
cursorColor: Colors.black54,
style: TextStyle(fontSize: 18, color: Colors.black54),
controller: TextEditingController(),
onSubmitted: (text) => searchLogic(context, text),
),
)))
]),
),
);
}
This is how I approached creating AppBar
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: buildSearchBar(context),
backgroundColor: Theme.of(context).brightness == Brightness.dark
? Colors.grey[850]
: Theme.of(context).accentColor,
),
body: CustomScrollView(
controller: scrollControllerSearchPage,
slivers: <Widget>[
SliverToBoxAdapter(
),
buildSearchBar(context),
],
),
);
}
I tried to create a column and fit it inside SizedBox but got these exceptions:
flutter: Another exception was thrown: A _RenderAppBarTitleBox expected a child of type RenderBox but received a child of type RenderSliverPadding.
flutter: Another exception was thrown: NoSuchMethodError: The method 'layout' was called on null.
flutter: Another exception was thrown: RenderBox was not laid out: _RenderAppBarTitleBox#9675d relayoutBoundary=up16 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#51f2d relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: Updated layout information required for RenderErrorBox#742c7 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.

Flutter - Login screen

I'm trying to make a login screen in Flutter. This login connect to e-mail and password, but have some problems. The errors revolves around the object was given an infinite size during layout. Attached is the code for my Dart class and the logged errors when running the code.
What are you guys getting out of the error code I cannot resolve?
Dart class
import 'package:flutter/material.dart';
import 'package:loja_virtual/models/user_model.dart';
import 'package:scoped_model/scoped_model.dart';
class FormContainer extends StatelessWidget {
final _emailController = TextEditingController();
final _passController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final _scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: ScopedModelDescendant<UserModel>(
builder: (context, child, model) {
if (model.isLoading)
return Center(child: CircularProgressIndicator(),);
return Container(
margin: EdgeInsets.symmetric(horizontal: 20),
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
style: TextStyle(
color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight", fontSize: 18.0),
filled: true,
fillColor: Colors.white24,
hintText: "E-mail",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.email,
color: Colors.white,
),
),
keyboardType: TextInputType.emailAddress,
validator: (text){
if(text.isEmpty || !text.contains("#")) return "E-mail inválido!";
},
),
SizedBox(height: 16.0,),
TextFormField(
style: TextStyle(
color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight", fontSize: 18.0),
filled: true,
fillColor: Colors.white24,
hintText: "Senha",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.lock_outline,
color: Colors.white,
),
),
obscureText: true,
validator: (text){
if(text.isEmpty || text.length < 6) return "Senha inválida!";
},
),
Align(
alignment: Alignment.centerRight,
child: FlatButton(
onPressed: (){
if(_emailController.text.isEmpty)
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Insira seu e-mail para recuperação!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 2),
)
);
else {
model.recoverPass(_emailController.text);
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Confira seu e-mail!"),
backgroundColor: Colors.purple,
duration: Duration(seconds: 2),
)
);
}
},
child: Text("Esqueci minha senha",
textAlign: TextAlign.right,
style: TextStyle(color: Colors.white, fontSize: 15.0),
),
padding: EdgeInsets.zero,
),
),
SizedBox(
height: 16,
),
SizedBox(
height: 80,
width: 80,
child: new FloatingActionButton(
backgroundColor: Colors.white30,
child: Text(
"Entrar",
style: TextStyle(
fontSize: 18.0,
),
),
onPressed: () {
if (_formKey.currentState.validate()) {
}
model.signIn(
email: _emailController.text,
pass: _passController.text,
onSuccess: _onSuccess,
onFail: _onFail
);
},
),
),
],
),
),
);
},
)
);
}
void _onSuccess() {
// Navigator.of(context).pop(); Esta dando erro
}
void _onFail() {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Falha ao Entrar!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 3),
)
);
}
}
Errors
I/flutter ( 4207): The following assertion was thrown during performLayout():
I/flutter ( 4207): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
I/flutter ( 4207): This probably means that it is a render object that tries to be as big as possible, but it was put inside
another render object that allows its children to pick their own size.
I/flutter ( 4207): The nearest ancestor providing an unbounded height constraint is: RenderIndexedSemantics#dc596
relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 4207): creator: IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter ( 4207): AutomaticKeepAlive ← SliverList ← SliverPadding ← Viewport ← IgnorePointer-[GlobalKey#aaf31] ←
I/flutter ( 4207): Semantics ← Listener ← _GestureSemantics ←
I/flutter ( 4207): RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#1430c] ←
I/flutter ( 4207): parentData: index=0; layoutOffset=0.0 (can use size)
I/flutter ( 4207): constraints: BoxConstraints(w=360.0, 0.0<=h<=Infinity)
I/flutter ( 4207): semantic boundary
I/flutter ( 4207): size: Size(360.0, Infinity)
I/flutter ( 4207): index: 0
I/flutter ( 4207): The constraints that applied to the RenderCustomMultiChildLayoutBox were:
I/flutter ( 4207): BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
I/flutter ( 4207): The exact size it was given was:
I/flutter ( 4207): Size(360.0, Infinity)
My Answer:
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:loja_virtual/models/user_model.dart';
import 'package:loja_virtual/widgets/sign_up_button.dart';
import 'package:flare_flutter/flare_actor.dart';
import 'package:scoped_model/scoped_model.dart';
class NewLoginScreen extends StatefulWidget {
#override
_NewLoginScreenState createState() => _NewLoginScreenState();
}
class _NewLoginScreenState extends State<NewLoginScreen> {
final _emailController = TextEditingController();
final _passController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final _scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(backgroundColor: Colors.transparent),
body: ScopedModelDescendant<UserModel>(
builder: (context, child, model) {
if (model.isLoading)
return Center(
child: CircularProgressIndicator(),
);
return Form(
key: _formKey,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background1.jpg"),
fit: BoxFit.cover)),
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: Image.asset(
"images/user1.png",
width: 130,
height: 130,
fit: BoxFit.contain,
),
),
TextFormField(
style: TextStyle(color: Colors.white),
controller: _emailController,
decoration: InputDecoration(
hintStyle: TextStyle(
color: Colors.white,
fontFamily: "WorkSansLight",
fontSize: 15.0),
filled: true,
fillColor: Colors.white24,
hintText: "E-mail",
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(
color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.email,
color: Colors.white,
),
),
keyboardType: TextInputType.emailAddress,
validator: (text) {
if (text.isEmpty || !text.contains("#"))
return "E-mail inválido!";
},
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(
color: Colors.white,
fontFamily: "WorkSansLight",
fontSize: 15.0),
filled: true,
fillColor: Colors.white24,
hintText: "Senha",
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(
color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.lock_outline,
color: Colors.white,
),
),
obscureText: true,
validator: (text) {
if (text.isEmpty || text.length < 6)
return "Senha inválida!";
},
),
Align(
alignment: Alignment.centerRight,
child: FlatButton(
onPressed: () {
if (_emailController.text.isEmpty)
_scaffoldKey.currentState
.showSnackBar(SnackBar(
content: Text(
"Insira seu e-mail para recuperação!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 2),
));
else {
model.recoverPass(_emailController.text);
_scaffoldKey.currentState
.showSnackBar(SnackBar(
content: Text("Confira seu e-mail!"),
backgroundColor: Colors.purple,
duration: Duration(seconds: 3),
));
}
},
child: Text(
"Esqueci minha senha",
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white, fontSize: 13.0),
),
padding: EdgeInsets.zero,
),
),
SizedBox(
height: 10,
),
SizedBox(
height: 80,
width: 80,
child: new FloatingActionButton(
backgroundColor: Colors.white30,
child: Text(
"Entrar",
style: TextStyle(
fontSize: 18.0,
),
),
onPressed: () {
if (_formKey.currentState.validate()) {}
model.signIn(
email: _emailController.text,
pass: _passController.text,
onSuccess: _onSuccess,
onFail: _onFail);
},
),
),
SignUpButton()
],
),
],
),
],
),
),
);
},
),
);
}
void _onSuccess() {
Navigator.of(context).pop();
}
void _onFail() {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Falha ao Entrar!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 3),
));
}
}
Now it's Ok. thx
Login
Try wrapping your ScopedModelDescendant in a Flexible (or a container with fixed size). By itself, it doesn't have any concept of what size it needs to be, so you need it to be a child of something that does have size constraints.

Renderflex error in flutter when Navigator pops current page?

I am building a settings page.
class SettingsScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Settings",
style: TextStyle(
color: primaryColor,
fontFamily: titleFontStyle
),
),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: primaryColor),
onPressed: () => Navigator.of(context).pop(),
),
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0.0,
),
backgroundColor: Colors.white,
body: Container(
width: double.infinity,
height: MediaQuery.of(context).size.height - 40.0,
padding: EdgeInsets.fromLTRB(20.0, 60.0, 20.0, 0.0),
child: ListView(
children: <Widget>[
Container(
child: TextField(
autofocus: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Username',
),
),
),
Container(
margin: EdgeInsets.only(top: 20.0),
child: RaisedButton(
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 40.0),
textColor: Colors.white,
color: primaryColor,
child: Text(
'Update',
style: TextStyle(
color: Colors.white
),
),
onPressed: () {},
),
),
],
),
),
);
}
}
I get an render flex overflow error whenever I try to press the back button.
The error message is as follows :-
The specific RenderFlex in question is:
I/flutter (18259): RenderFlex#17a8f relayoutBoundary=up1 OVERFLOWING
I/flutter (18259): creator: Column ← MediaQuery ← LayoutId
I have tried wrapping the Containers in SingleChildScrollView() but it doesn't work.
I used to use Column() before using ListView() but that didn't work either.
This is caused by soft keyboard , add this to scaffold widget
resizeToAvoidBottomInset : false
or
resizeToAvoidBottomPadding: false,
it existe different ways to avoid that but more important the only fix that error, that could we done with what C4C said, its understand what happens and you can know more about this error reading about it in this post from Scott Stoll from Flutter Community
You could use also Expanded or Flexible widgets to avoid this, you will understand more about this errors after read the 4 post he did.
Also you can remove the size from the container and add the property shrinkWrap: true, of the listview.