i am new to flutter , i am trying to add a GridView to the end of my listview,my goal is in the end of the screen i find the gridview , but i have errors :
The relevant error-causing widget was:
GridView file:///C:/Users/Fares/AndroidStudioProjects/tl_fantasy/lib/tl/tl.dart:211:33
When the exception was thrown, this was the stack:
#0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1356:15)
#1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1417:6)
#2 RenderObject.layout (package:flutter/src/rendering/object.dart:1756:9)
#3 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:113:14)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
this error show up only when i add in the end of the file the container of gridview
hero my code :
import 'package:flutter/material.dart';
class TL extends StatelessWidget{
List<String> images = [
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png"
];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.purple, Colors.blue])
),
child: ListView(
children: [
SizedBox(
height: 20,
),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Text(
"Tunisian League",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w900, color: Colors.white),
),
),
SizedBox(
height: 30,
),
Container(
margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
child: Column(
children: [
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 10,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 10,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 30,
)
],
),
),
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
itemCount: images.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return Image.network(images[index]);
},
)
)
],
),
)
);
}
}
I hope that i can find a solution for that problem
Add the 'shrinkWrap' property to the GridView.
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
shrinkWrap: true,
itemCount: images.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return Image.network(images[index]);
},
)
)
For more details on why the 'shrinkWrap' property is needed, you can refer to this : What does the shrink wrap property do in flutter?
All you have to do is add shrinkWrap to your Gridview as follows :
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
shrinkWrap: true,
itemCount: images.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index) {
return Image.network(images[index]);;
},
)
)
Related
The widget inside the gridView overlap each other , the bottom portion of the widget is overlapped by another widget , How to avoid overlap in widget inside GridView?I want to avoid the overlap amoung the widget.
Here is my codes
It contain a gridview builder containing the widget, the widget is made by stack , position.fill
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:iconsax/iconsax.dart';
class WorkshopsCloseToYouPage extends StatelessWidget {
const WorkshopsCloseToYouPage({super.key});
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: GridView.builder(
itemCount: 6,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0),
itemBuilder: (BuildContext context, int index) {
return workshopCard();
},
),
),
);
}
Stack workshopCard() {
return Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('assets/workshop_image.png'),
fit: BoxFit.cover,
),
),
),
Positioned.fill(
bottom: -100,
child: Align(
alignment: Alignment.bottomCenter,
child: Card(
margin: const EdgeInsets.all(5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Pottery Throwing Taster Class",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(
height: 5,
),
Row(
children: [
SizedBox(
width: 100,
child: Column(
children: [
Row(
children: [
Icon(
Iconsax.location5,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text(
"Honslow",
// style: TextStyle(fontSize: 8),
)
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.profile_2user,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("1 to 15")
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.tag_right,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("1 to 15")
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.star,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("5(37)")
],
),
],
),
),
ElevatedButton(
onPressed: () {},
style: TextButton.styleFrom(
minimumSize: const Size(70, 35),
maximumSize: const Size(70, 35),
backgroundColor: Color(0xFF0c3cac),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20))),
child: Row(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Text(
"Join",
style: TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
Icon(size: 5, Icons.arrow_forward_ios),
Icon(
color: Color.fromARGB(255, 231, 227, 227),
size: 5,
Icons.arrow_forward_ios),
Icon(
color: Color.fromARGB(255, 181, 180, 180),
size: 5,
Icons.arrow_forward_ios),
],
)),
],
),
],
),
)),
),
)
],
);
}
}
Output page showing the widget overlap
i am beginner in Flutter , i am trying to create a gridview builder with a card that contains an image, the gridview. builder in the bottom works fine but the gridview builder on the top do not load any image, the difference of the both gridviews is that the one that have problem : the image is inside a card,
I do not have any idea why the second works and the one on the top do not do that even they use the same assets
the error i am getting is about Invalid argument(s): No host specified in URI for every asset
import 'package:flutter/material.dart';
import 'package:footyappp/clubs/Clubs.dart';
import 'package:footyappp/results/results.dart';
import 'package:footyappp/schedules/schedules.dart';
import 'package:footyappp/stats/player_goals.dart';
import 'package:footyappp/tables%20copy/league_board.dart';
import 'package:footyappp/stats/player_assists.dart';
import 'package:footyappp/stats/player_red_cards.dart';
import 'package:footyappp/stats/player_yellow_cards.dart';
class Statss extends StatelessWidget {
List<String> images = [
"Assets/tt.jpg",
"Assets/qatarairways.jpg",
"Assets/LOGO_Danao.jpg",
"Assets/delice.jpg"
];
List<String> menu = [
"Assets/tt.jpg",
"Assets/qatarairways.jpg",
"Assets/LOGO_Danao.jpg",
"Assets/delice.jpg"
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Stats"),
backgroundColor: Colors.blue[300],
elevation: 0.0,
),
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.purple, Colors.blue])),
child: ListView(
children: [
SizedBox(
height: 20,
),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Text(
"Statistiques",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w900,
color: Colors.white),
),
),
SizedBox(
height: 30,
),
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
shrinkWrap: true,
itemCount: menu.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 1.0,
mainAxisSpacing: 1.0),
itemBuilder: (BuildContext context, int index) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Column(
children: <Widget>[
Container(
height: 60,
width: 60,
child:
Image.network(menu[index]),
),
const SizedBox(width:10.0),
],
),
),
);
},
),
),
Container(
margin: EdgeInsets.fromLTRB(15, 30, 15, 0),
child: Column(
children: [
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
height: 40,
child: RaisedButton(
child: Align(
child: Text(
"Top Scorers",
style: TextStyle(fontSize: 17),
textAlign: TextAlign.right,
),
alignment: Alignment.centerLeft,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Scorers()),
);
},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
height: 40,
child: RaisedButton(
child: Align(
child: Text(
"Top Assists",
style: TextStyle(fontSize: 17),
textAlign: TextAlign.right,
),
alignment: Alignment.centerLeft,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Assists()),
);
},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
height: 40,
child: RaisedButton(
child: Align(
child: Text(
"Yellow Cards",
style: TextStyle(fontSize: 17),
textAlign: TextAlign.right,
),
alignment: Alignment.centerLeft,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => YellowCards()),
);
},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
height: 40,
child: RaisedButton(
child: Align(
child: Text(
"Red Cards",
style: TextStyle(fontSize: 17),
textAlign: TextAlign.right,
),
alignment: Alignment.centerLeft,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => RedCards()),
);
},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
SizedBox(
height: 30,
)
],
),
),
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
shrinkWrap: true,
itemCount: images.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0),
itemBuilder: (BuildContext context, int index) {
return Image.asset(images[index]);
},
),
),
SizedBox(
height: 30,
)
],
),
));
}
}
here how it looks:
i am tryin to make it works
This is because you are using Image.network(menu[index]) for the top gridview.
change it to
Image.asset(menu[index]), it'll work, because you are loading your images from your assets, and not anything from the network.
i have a problem to get ride of a white space in grid view cell in fluter, especially when the device is in landscape orientation, the code is :
return Container(
padding: EdgeInsets.only(top: 15),
child: GridView.builder(
itemCount: recipesList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 0.0,
mainAxisSpacing: 0.0,
//childAspectRatio: 1,
),
itemBuilder: (BuildContext context, int index) {
Recipe recipe = recipesList[index];
return Dismissible(
key: UniqueKey(),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
margin: EdgeInsets.all(8),
color: Colors.white,
elevation: 5,
child: InkWell(
onTap: (){},
child: Column(
// padding: EdgeInsets.zero,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Image.asset(
'images/${recipe.picture}',
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.topLeft,
//margin: EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${recipe.id} - ${recipe.title}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
),
),
Text(
'by Unknown Chef',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w300,
),
),
Row(
children: [
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.orange,
size: 20.0,
),
Icon(
Icons.star,
color: Colors.grey[400],
size: 20.0,
),
Icon(
Icons.star,
color: Colors.grey[400],
size: 20.0,
),
],
)
],
),
),
),
IconButton(
icon: recipe.isFavorite
? Icon(Icons.favorite, color: Colors.red)
: Icon(Icons.favorite_outline_outlined,
color: Colors.grey),
iconSize: 36,
onPressed: (){},
),
],
),
),
],
),
),
),
);
},
),
);
the result is fine as below:
but in landscape mode it's not what i want
the desired result would be like this
How can I make this cards to look like this in landscape orientation?
The default childAspectRatio is 1.0 meaning width = height. If you want to get the expected result, wrap your container in Expanded widget and remove Image height property as following
Expanded(
child: Container(
child: Image.asset(
'images/${recipe.picture}',
width: double.infinity,
fit: BoxFit.cover,
),
),
)
Check the Bottom White space
This below is the code of the Root widget. How to remove the empty area by default, and make this adaptable to every device?
#override
Widget build(BuildContext context) {
var padding = MediaQuery.of(context).padding;
var height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: ConstrainedBox(
constraints:
BoxConstraints(minHeight: MediaQuery.of(context).size.height),
// height: height,
child: Stack(
children: <Widget>[
Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
SizedBox(
height: padding.top,
),
Container(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 20, top: 20),
child: GestureDetector(
onTap: () {
print("Trouble Logging in?");
},
child: Text(
"Trouble logging in?",
style: TextStyle(
fontSize: 15,
color: Color.fromRGBO(8, 199, 68, 1),
),
),
),
),
),
Container(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 30, left: 50),
child: Text(
"Login",
style: TextStyle(
fontSize: 50,
color: Color.fromRGBO(69, 69, 69, 1),
),
),
),
),
Container(
alignment: Alignment.centerLeft,
child: Padding(
padding:
const EdgeInsets.only(top: 50, left: 60, right: 40),
child: Row(
children: <Widget>[
Text(
"Email",
style: TextStyle(
fontSize: 18,
color: Color.fromRGBO(82, 93, 92, 1),
),
),
Expanded(
child: Container(),
),
Visibility(
visible: emailError,
child: Text(
"Invalid Email",
style: TextStyle(
color: Colors.red[400],
),
),
)
],
),
),
),
Container(
alignment: Alignment.center,
child: Padding(
padding:
const EdgeInsets.only(top: 10, left: 40, right: 40),
child: TextFormField(
validator: (_input) {
if (_input.isEmpty ||
!_input.contains("#") ||
!_input.contains(".")) {
return "Invalid Email";
}
return null;
},
controller: emailcontroller,
onChanged: (value) => {
setState(() {
email = value;
})
},
style: TextStyle(fontSize: 20),
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 13),
filled: true,
fillColor: emailError
? Colors.red[100]
: Color.fromRGBO(246, 246, 246, 1),
prefixIcon: Icon(Icons.alternate_email),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30)),
),
),
),
),
Container(
alignment: Alignment.centerLeft,
child: Padding(
padding:
const EdgeInsets.only(top: 30, left: 60, right: 40),
child: Row(
children: <Widget>[
Text("Password",
style: TextStyle(
fontSize: 18,
color: Color.fromRGBO(82, 93, 92, 1))),
Expanded(
child: Container(),
),
Visibility(
visible: passwordError,
child: Text("Incorrect Password",
style: TextStyle(color: Colors.red[400])),
)
],
),
),
),
Container(
alignment: Alignment.center,
child: Padding(
padding:
const EdgeInsets.only(top: 10, left: 40, right: 40),
child: TextFormField(
validator: (_input) {
if (_input.isEmpty || _input.length < 8) {
return "Invalid Password";
}
return null;
},
controller: passwordcontroller,
onChanged: (value) => {
setState(
() {
password = value;
},
)
},
obscureText: true,
style: TextStyle(fontSize: 20),
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 13),
filled: true,
fillColor: passwordError
? Colors.red[100]
: Color.fromRGBO(246, 246, 246, 1),
prefixIcon: Icon(Icons.lock_outline),
suffixIcon: GestureDetector(
onTap: () => {
setState(() {
hide = !hide;
})
},
child: Icon(
hide
? Icons.visibility_off
: Icons.visibility,
color: Colors.black),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
),
),
Container(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 60, top: 20),
child: GestureDetector(
onTap: null,
child: Text(
"Forgot password?",
style: TextStyle(
fontSize: 16,
color: Color.fromRGBO(8, 199, 68, 1),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Container(
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
gradient: LinearGradient(
colors: [
Color.fromRGBO(3, 163, 99, 1),
Color.fromRGBO(8, 199, 68, 1)
],
begin: Alignment.centerLeft,
end: Alignment.centerRight)),
alignment: Alignment.center,
child: MaterialButton(
onPressed: () {
if (_formKey.currentState.validate()) {
signin();
}
},
// signin,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Log In",
style: TextStyle(
color: Colors.white, fontSize: 18)),
),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Icon(Icons.exit_to_app,
color: Colors.white),
)
],
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Don't have an account? ",
style: TextStyle(
fontSize: 15, fontFamily: 'Mulish-Reg')),
GestureDetector(
onTap: () =>
Navigator.of(context).push(register()),
child: Text("Sign up",
style: TextStyle(fontSize: 15)))
],
)),
Padding(
padding: EdgeInsets.only(top: 30, left: 30, right: 30),
child: Image.asset('assets/or.png')),
Padding(
padding: EdgeInsets.only(top: 30, bottom: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: GestureDetector(
onTap: () => facebook(),
child: Image.asset(
'assets/fb.png',
scale: 2.5,
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: GestureDetector(
onTap: () => google(),
child: Image.asset(
'assets/google.png',
scale: 2.5,
),
),
),
],
),
),
// SizedBox(
// height: padding.top,
// ),
Container(
width: double.maxFinite,
alignment: Alignment.bottomCenter,
child: Image.asset('assets/bottom.png'),
),
],
),
),
loading
? Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.black26,
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Color.fromRGBO(3, 163, 99, 1),
),
),
),
)
: Positioned(
bottom: 0,
height: 0,
width: 0,
child: Container(),
),
],
),
),
),
);
}
}
The bottom.png in the Container() in Stack is to be fixed at the bottom of the screen
Container(
width: double.maxFinite,
alignment: Alignment.bottomCenter,
child: Image.asset('assets/bottom.png'),
),
this container I want to be at the bottom of the screen removing the white space at the end
I am new in flutter and I try to make scrollable UI.
I try to add Expanded widgets, ListViews Widgets , SingleChildScrollView widgets but didn't get the expected result.
Also, I try to wrap the stack inside Container and then inside SingleChildScrollView. But it throws error.
I tried many aspects to make my homepage scrollable. But, I got errors (Mentioned below)
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#e1279 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: _RenderColoredBox#89cc6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#9505f NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 549 pos 12: 'child.hasSize': is not true.
GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
new TextEditingController().clear();
},
child: Stack(
children: <Widget>[
Container(
height: 200,
child: TopBar(),
),
Container(
margin: EdgeInsets.only(top: 55),
child: Text(
"PriceTrackers",
style: TextStyle(
color: Colors.white,
fontSize: 50.0,
fontWeight: FontWeight.w900,
),
),
),
Container(
margin: EdgeInsets.fromLTRB(265, 0, 0, 0),
child: Text(
".",
style: TextStyle(
fontSize: 120,
color: Colors.white,
),
)),
ListView(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 200),
child: Form(
key: _formKey,
child: Column(children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.store),
Text(
"Supported Store",
style: TextStyle(
fontSize: 20,
color: Colors.green,
),
),
Image.asset(
"Assets/img/amazon.png",
width: 20,
),
Image.asset(
"Assets/img/flipkart.png",
width: 20,
),
Image.asset(
"Assets/img/ajio.png",
width: 20,
),
Image.asset(
"Assets/img/snapdeal.png",
width: 20,
),
Image.asset(
"Assets/img/ss.jpg",
width: 20,
),
],
),
margin: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
// boxShadow: [
// BoxShadow(color: Colors.white, spreadRadius: 3),
// ],
),
),
// Add TextFormFields and RaisedButton here.
TextFormField(
controller: _controller,
enableInteractiveSelection: true,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.green),
borderRadius: BorderRadius.circular(20),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red,
),
borderRadius: BorderRadius.circular(20),
),
hintText: "Enter Product URL",
suffixIcon: Icon(Icons.search),
),
// onFieldSubmitted: (term){
// FocusScope.of(context).unfocus();
// _controller.clear();
// },
showCursor: true,
autofocus: false,
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
} else if (!value.contains("amazon") ||
!value.contains("flipkart") ||
!value.contains("myntra")) {
return "Please Enter Supported Store URL";
}
return null;
},
),
RaisedButton.icon(
icon: Icon(
Icons.search,
color: Colors.white,
),
color: Colors.black,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
elevation: 20.0,
onPressed: () async {
// Validate returns true if the form is valid, otherwise false.
if (_formKey.currentState.validate()) {
setState(() {
createAlbum(_controller.text).then((value) => {
Navigator.push(
context,
EnterExitRoute(
exitPage: HomePage(),
enterPage: LineChartSample2(
getData: value)))
});
});
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
'Processing Data',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.green,
));
// If the form is valid, display a snackbar. In the real world,
// you'd often call a server or save the information in a database.
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => LineChartSample2()),
// );
}
},
label: Text(
'View Price Graph',
style: TextStyle(
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
width: 380,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.blue[200],
blurRadius: 25.0, // soften the shadow
spreadRadius: 5.0, //extend the shadow
offset: Offset(
15.0, // Move to right 10 horizontally
15.0, // Move to bottom 10 Vertically
),
)
],
),
child: Row(
children: <Widget>[
Container(
width: 130,
height: 130,
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
child: FadeInImage(
fit: BoxFit.scaleDown,
// here `bytes` is a Uint8List containing the bytes for the in-memory image
placeholder: AssetImage("Assets/img/bag.png"),
image: NetworkImage(
'https://images-na.ssl-images-amazon.com/images/I/81j14WXbc%2BL._UL1500_.jpg'),
),
),
Expanded(
child: Container(
padding: EdgeInsets.fromLTRB(0, 20, 10, 0),
child: Column(
children: <Widget>[
Text(
"Redux Analogue Blue Dial Men’s &S... ",
maxLines: 2,
softWrap: true,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
color: Colors.black),
),
Container(
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
children: <Widget>[
OutlineButton.icon(
onPressed: () => {},
icon: Icon(Icons.shopping_basket),
label: Text("But Now #28939")),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Avg Price : 7,98,374",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w900,
),
),
Text(
"Avg Price :34,43,343",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w900,
),
)
],
),
Container(
margin: EdgeInsets.all(5),
),
FlatButton.icon(
icon: Icon(Icons.show_chart),
color: Colors.black,
textColor: Colors.white,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
padding: EdgeInsets.fromLTRB(
20, 5, 20, 5),
splashColor: Colors.blueAccent,
onPressed: () {
/*...*/
},
label: Text(
"Show Price Graph",
style: TextStyle(fontSize: 15.0),
),
)
],
)),
],
),
))
],
),
),
])),
),
],
),
Container(
margin: EdgeInsets.only(top: 650),
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8),
child: const Text("He'd have you all unravel at the"),
color: Colors.teal[100],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
],
)),
],
));
You can copy paste run full code below
Step 1: Use LayoutBuilder and ConstrainedBox
return LayoutBuilder(builder: (context, constraints) {
...
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: double.infinity),
child: Stack(
Step 2: Change ListView to Column
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Column(
Step 3: GridView use shrinkWrap: true
working demo
full code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
TextEditingController().clear();
},
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: double.infinity),
child: Stack(
children: <Widget>[
Container(
height: 200,
child: Text("TopBar()"),
),
Container(
margin: EdgeInsets.only(top: 55),
child: Text(
"PriceTrackers",
style: TextStyle(
color: Colors.black,
fontSize: 50.0,
fontWeight: FontWeight.w900,
),
),
),
Container(
margin: EdgeInsets.fromLTRB(265, 0, 0, 0),
child: Text(
".",
style: TextStyle(
fontSize: 120,
color: Colors.white,
),
)),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 200),
child: Form(
//key: _formKey,
child: Column(children: <Widget>[
Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.store),
Text(
"Supported Store",
style: TextStyle(
fontSize: 20,
color: Colors.green,
),
),
Image.network(
'https://picsum.photos/250?image=9',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=10',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=11',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=12',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=13',
width: 20,
),
],
),
margin: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
// boxShadow: [
// BoxShadow(color: Colors.white, spreadRadius: 3),
// ],
),
),
// Add TextFormFields and RaisedButton here.
TextFormField(
//controller: _controller,
enableInteractiveSelection: true,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.green),
borderRadius: BorderRadius.circular(20),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red,
),
borderRadius: BorderRadius.circular(20),
),
hintText: "Enter Product URL",
suffixIcon: Icon(Icons.search),
),
// onFieldSubmitted: (term){
// FocusScope.of(context).unfocus();
// _controller.clear();
// },
showCursor: true,
autofocus: false,
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
} else if (!value.contains("amazon") ||
!value.contains("flipkart") ||
!value.contains("myntra")) {
return "Please Enter Supported Store URL";
}
return null;
},
),
RaisedButton.icon(
icon: Icon(
Icons.search,
color: Colors.white,
),
color: Colors.black,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
elevation: 20.0,
onPressed: () async {
// Validate returns true if the form is valid, otherwise false.
},
label: Text(
'View Price Graph',
style: TextStyle(
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
width: 380,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.blue[200],
blurRadius: 25.0,
// soften the shadow
spreadRadius: 5.0,
//extend the shadow
offset: Offset(
15.0,
// Move to right 10 horizontally
15.0, // Move to bottom 10 Vertically
),
)
],
),
child: Row(
children: <Widget>[
Container(
width: 130,
height: 130,
padding:
EdgeInsets.fromLTRB(5, 10, 5, 10),
child: FadeInImage(
fit: BoxFit.scaleDown,
// here `bytes` is a Uint8List containing the bytes for the in-memory image
placeholder: NetworkImage(
"https://picsum.photos/250?image=9"),
image: NetworkImage(
'https://images-na.ssl-images-amazon.com/images/I/81j14WXbc%2BL._UL1500_.jpg'),
),
),
Expanded(
child: Container(
padding:
EdgeInsets.fromLTRB(0, 20, 10, 0),
child: Column(
children: <Widget>[
Text(
"Redux Analogue Blue Dial Men’s &S... ",
maxLines: 2,
softWrap: true,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
color: Colors.black),
),
Container(
margin: EdgeInsets.fromLTRB(
0, 10, 0, 0),
child: Column(
children: <Widget>[
OutlineButton.icon(
onPressed: () => {},
icon: Icon(Icons
.shopping_basket),
label: Text(
"But Now #28939")),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: <Widget>[
Text(
"Avg Price : 7,98,374",
style: TextStyle(
fontSize: 10,
fontWeight:
FontWeight.w900,
),
),
Text(
"Avg Price :34,43,343",
style: TextStyle(
fontSize: 10,
fontWeight:
FontWeight.w900,
),
)
],
),
Container(
margin: EdgeInsets.all(5),
),
FlatButton.icon(
icon:
Icon(Icons.show_chart),
color: Colors.black,
textColor: Colors.white,
disabledColor: Colors.grey,
disabledTextColor:
Colors.black,
padding:
EdgeInsets.fromLTRB(
20, 5, 20, 5),
splashColor:
Colors.blueAccent,
onPressed: () {
/*...*/
},
label: Text(
"Show Price Graph",
style: TextStyle(
fontSize: 15.0),
),
)
],
)),
],
),
))
],
),
),
])),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 650),
child: GridView.count(
shrinkWrap: true,
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8),
child: const Text(
"He'd have you all unravel at the"),
color: Colors.teal[100],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
],
)),
],
),
),
)),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
});
}
}
You need to remove height from container.
SingleChildScrollView(
child: Container(
child: Stack(
children: <Widget>[
])))