displaying matching id , flutter - flutter

I'm new to flutter, I'm trying to show cards in categories, I've made a module with the categories and items, including id for the categories and matching id for the item(one item can be in multiple categories ) but I don't know how to sort them
this is the main screen
Widget _buildIcon(int index) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: GestureDetector(
onTap: () {
setState(() {
_selectedIndex = index;
String id = DUMMY_CATEGORIES[index].id;
print(id);
});
},
child: Container(
height: 45,
width: 100,
decoration: BoxDecoration(
color: _selectedIndex == index
? Color.fromRGBO(126, 214, 223, 0.5)
: Color.fromRGBO(200, 214, 229,0.3),
borderRadius: BorderRadius.circular(80)),
child: Center(
child: Text(
DUMMY_CATEGORIES[index].title, style: TextStyle(color: _selectedIndex==index ?Color.fromRGBO(16, 172, 132, 1) : Colors.black, ),
),
),
),
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(right: 10, top: 20),
alignment: Alignment.topRight,
child: IconButton(
icon: Icon(
Icons.search,
size: 25,
),
)),
Container(
padding: EdgeInsets.only(left: 10),
alignment: Alignment.topLeft,
child: Text(
'Make it Bread',
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
)),
],
),
SizedBox(
height: 30,
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: DUMMY_CATEGORIES
.asMap()
.entries
.map((MapEntry map) => _buildIcon(map.key))
.toList()
),
),
NewMealIteam(),
],
),
);
}
}
and this is the item
Widget build(BuildContext context) {
return Padding(padding: EdgeInsets.symmetric(horizontal: 10, vertical: 45),
child: Container(
height: 450,
//color: Colors.orange,
child: ListView.builder(itemCount: mealList.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context ,int index){
Meal mealLists = mealList[index];
return Container(
width: 280,
child: Stack(children: <Widget>[
Container(
height: 450,
margin: EdgeInsets.all(10),
padding: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20),
color: Colors.red,
image: DecorationImage(
image: AssetImage('assets/dough.png'
),fit: BoxFit.fill
),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(3.0, 2.0), // shadow direction: bottom right
)
],),
),
Positioned(bottom :20 ,left: 20,child: Column(
children: <Widget>[
Container(width: 170,
padding: EdgeInsets.symmetric(vertical: 25),
child: Text(mealLists.title,style: TextStyle(color:Colors.white,fontSize: 32),textAlign: TextAlign.start,overflow: TextOverflow.fade
,),
),
Padding(
padding: EdgeInsets.all(2),
child: Container(width:220,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.schedule),
SizedBox(
width: 6,
),
Text('${mealLists.duration} min'),
],
),
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.work),
SizedBox(
width: 8,
),
],
),
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.monetization_on),
SizedBox(
width: 6,
),
// Text('${durations} min'),
],
),
],
),
),
)
],
))
],),
);
},
),
),
);
}
}
this is example for the module list
Category(
id: 'c1',
title: 'sour bread',
),
Meal(
id: 'm1',
categories: [
'c1',
'c2',
],
title: 'Sour Dough',
),
thanks

Related

Exception caught by widgets library: Incorrect use of ParentDataWidget

The same 2 errors appear in 2 different files when I run my flutter program, does anyone know how to fix this? this is my code
code for list restaurant.dart
import 'package:flutter/material.dart';
import 'package:resto_app/data/model/restaurant_list.dart';
import 'package:resto_app/ui/detail_page.dart';
class CardRestaurant extends StatelessWidget {
final Restaurant restaurant;
const CardRestaurant({Key? key, required this.restaurant}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: InkWell(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return RestaurantDetailPage(idrestaurant: restaurant.id);
}));
},
child: Stack(
children: <Widget>[
Container(
margin:
const EdgeInsets.only(left: 40, top: 5, right: 20, bottom: 5),
height: 170.0,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.lime.shade100,
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(
padding: const EdgeInsets.only(
left: 200, top: 20, right: 20, bottom: 20),
child: Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 120.0,
child: Expanded(child: Text(restaurant.name)),
),
_sizebox(10),
Row(
children: [
_icon(Icons.star_rate, 20, Colors.yellow),
Text(
' ${restaurant.rating}',
),
],
)
],
),
),
),
),
Positioned(
left: 20.0,
top: 15.0,
bottom: 15.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Hero(
tag: restaurant.pictureId,
child: Image.network(
"https://restaurant-api.dicoding.dev/images/small/" +
restaurant.pictureId,
width: 200,
fit: BoxFit.cover,
),
),
),
),
],
),
),
);
}
}
Widget _sizebox(double height) {
return SizedBox(
height: height,
);
}
Widget _icon(IconData icon, double size, Color color) {
return Icon(
icon,
size: size,
color: color,
);
}
and my detailrestaurant.dart code
`
`import 'package:flutter/material.dart';
import 'package:resto_app/data/model/restaurants_detail.dart';
import 'package:resto_app/common/constant.dart';
class RestaurantDetail extends StatelessWidget {
static const routeName = '/restaurant_detail';
final Restaurant restaurant;
const RestaurantDetail({Key? key, required this.restaurant})
: super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Hero(
tag: restaurant.pictureId,
child: Image.network(
"https://restaurant-api.dicoding.dev/images/medium/" +
restaurant.pictureId,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(restaurant.name),
_sizebox(10),
Row(
children: [
_icon(Icons.location_city, 20, Colors.grey),
const SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(restaurant.city),
Text(restaurant.address),
],
)
],
),
],
),
Row(
children: [
_icon(Icons.star_rate, 20, Colors.yellow),
Text(
' ${restaurant.rating}',
),
],
)
],
),
),
_barrierContent(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.only(top: 10, right: 20, left: 20),
child: Text('Description'),
),
Container(
padding: const EdgeInsets.only(
top: 10, right: 20, left: 20, bottom: 20),
width: double.infinity,
child: Text(restaurant.description)),
],
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Category'),
ListBody(
children: restaurant.categories.map((food) {
return Text(
'- ${food.name}',
);
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Menu Food'),
ListBody(
children: restaurant.menus.foods.map((categori) {
return Text(
'- ${categori.name}',
);
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Menu Drink'),
ListBody(
children: restaurant.menus.drinks.map((drink) {
return Text('- ${drink.name}');
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 10),
child: Column(
children: [
Text('Comment'),
ListBody(
children: restaurant.customerReviews.map((review) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Expanded(
child: Row(children: [
Container(
width: 40,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue),
child: Center(
child: Text(
review.name.characters.elementAt(0),
style: const TextStyle(
color: Colors.white, fontSize: 20),
)),
),
const SizedBox(
width: 15,
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
review.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold),
),
Text(
' ${review.date}',
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade500),
)
],
),
SizedBox(
width: 270,
child: Text(
review.review,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
)
],
),
)
]),
),
);
}).toList(),
),
],
),
),
_barrierContent()
],
),
],
),
),
),
);
}
}
Widget _barrierContent() {
return Container(
height: 10,
color: Colors.grey.shade200,
);
}
Widget _sizebox(double height) {
return SizedBox(
height: height,
);
}
Widget _icon(IconData icon, double size, Color color) {
return Icon(
icon,
size: size,
color: color,
);
}
`
``
error
The same 2 errors appear in 2 different files when I run my flutter program, does anyone know how to fix this?
child: Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 120.0,
child: Expanded(child: Text(restaurant.name)),
),
parent of Expanded must be Stack, Column, Row but in your example it's wrong
You should use Expanded only within a Column, Row or Flex & that to its top most child only
Here you have use Expanded widget inside padding widget which is inside stack and also you can't use Expanded inside stack, so it causing this ParentDataWidget Error
code for list restaurant.dart
class CardRestaurant extends StatelessWidget {
final Restaurant restaurant;
const CardRestaurant({Key? key, required this.restaurant}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: InkWell(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return RestaurantDetailPage(idrestaurant: restaurant.id);
}));
},
child: Stack( //---------------
children: <Widget>[
Container(
margin:
const EdgeInsets.only(left: 40, top: 5, right: 20, bottom: 5),
height: 170.0,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.lime.shade100,
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(//---------
padding: const EdgeInsets.only(
left: 200, top: 20, right: 20, bottom: 20),
child: Expanded(//--------- you can't use expanded inside Stack
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 120.0,
child: Expanded(child: Text(restaurant.name)),
),
_sizebox(10),
and my detailrestaurant.dart code
class RestaurantDetail extends StatelessWidget {
static const routeName = '/restaurant_detail';
final Restaurant restaurant;
const RestaurantDetail({Key? key, required this.restaurant})
: super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Hero(
tag: restaurant.pictureId,
child: Image.network(
"https://restaurant-api.dicoding.dev/images/medium/" +
restaurant.pictureId,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(restaurant.name),
_sizebox(10),
Row(
children: [
_icon(Icons.location_city, 20, Colors.grey),
const SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(restaurant.city),
Text(restaurant.address),
],
)
],
),
],
),
Row(
children: [
_icon(Icons.star_rate, 20, Colors.yellow),
Text(
' ${restaurant.rating}',
),
],
)
],
),
),
_barrierContent(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.only(top: 10, right: 20, left: 20),
child: Text('Description'),
),
Container(
padding: const EdgeInsets.only(
top: 10, right: 20, left: 20, bottom: 20),
width: double.infinity,
child: Text(restaurant.description)),
],
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Category'),
ListBody(
children: restaurant.categories.map((food) {
return Text(
'- ${food.name}',
);
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Menu Food'),
ListBody(
children: restaurant.menus.foods.map((categori) {
return Text(
'- ${categori.name}',
);
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Column(
children: [
Text('Menu Drink'),
ListBody(
children: restaurant.menus.drinks.map((drink) {
return Text('- ${drink.name}');
}).toList(),
),
],
),
),
_barrierContent(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 10),
child: Column(
children: [
Text('Comment'),
ListBody(//--- this is top most child
children: restaurant.customerReviews.map((review) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Expanded(//--------- This causing problem here, you can only use Exapnded to column top most child
child: Row(children: [
Container(
width: 40,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue),
child: Center(
child: Text(
review.name.characters.elementAt(0),
style: const TextStyle(
color: Colors.white, fontSize: 20),
)),
),
const SizedBox(
width: 15,
),
Expanded(//---- This one also causing Problem
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
review.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold),
),
Text(
' ${review.date}',
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade500),
)
],
),
SizedBox(
width: 270,
child: Text(
review.review,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
)
],
),
)
]),
),
);
}).toList(),
),
],
),
),
_barrierContent()
],
),
],
),
),
),
);
}
}
Keep this point in mind to avoid basic error
Most common one Expanded can only use to a descendant of Column,Row & Flex
Don't use Positioned under Row or Column instead use Align
Under ListView don't use Spacer instead use SizedBox
Hope this might help you to solve your Error
Happy Learning!!!

RenderBox was not laid out: RenderCustomPaint#cd52e relayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

class _MainFoodPageState extends State<MainFoodPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Container(
//header
child: Container(
margin: EdgeInsets.only(top: 45, bottom: 15),
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
BigText(
text: "Iran",
color: AppColors.mainColor,
),
Row(
children: [
SmallText(
text: "Tehran",
color: Colors.black54,
),
Icon(Icons.arrow_drop_down)
],
),
],
),
Center(
child: Container(
width: 45,
height: 45,
child: Icon(
Icons.search,
color: Colors.white,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: AppColors.mainColor),
),
)
],
),
),
),
),
//slider
Expanded(
child: SingleChildScrollView(
child: FoodPageBody(),
),
),
],
),
);
}
}
`---------------------------------------
#override
Widget build(BuildContext context) {
return Column(
children: [
//slider
Container(
height: 320,
child: PageView.builder(
controller: pageController,
itemCount: itemCount,
itemBuilder: (context, position) {
return _buildPageItem(position);
}),
),
//dots
DotsIndicator(
dotsCount: itemCount,
position: _currentPageValue,
decorator: DotsDecorator(
color: AppColors.mainColor,
size: const Size.square(9.0),
activeSize: const Size(18.0, 9.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
),
),
//popular
SizedBox(
height: 30,
),
Container(
margin: EdgeInsets.only(left: 30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
BigText(text: "Popular"),
SizedBox(
width: 10,
),
Container(
margin: EdgeInsets.only(bottom: 3),
child: BigText(
text: ".",
color: Colors.black26,
),
),
SizedBox(
width: 10,
),
Container(
margin: EdgeInsets.only(bottom: 2),
child: SmallText(text: "Food pairing"),
),
//list of foods
Container(
child: ListView.builder(
itemCount: 10,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container();
},
),
),
],
),
)
],
);
}
i cant make a ListView.builder (flutter)

How can I make a Flutter Scaffold scroll to not have TextFields covered

I have a somewhat complicated widget tree and can't figure this out. I've tried wrapping the Scaffold body in a SingleChildScrollView but for some reason it just makes the Container shrink and does not scroll. Here is the build function code:
return Stack(
children: [
Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
children: [
background(),
Padding(
padding: const EdgeInsets.only(top: 55),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/logo.png', height: 100),
const SizedBox(width: 5),
const Text('GLOBE',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Color(0xFF7FCCDC)))
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 175, left: 35, right: 35, bottom: 50),
child: Container(
decoration: BoxDecoration(
color: const Color(0xFFFCFBF4).withOpacity(0.5),
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('Welcome!',
style: TextStyle(
fontSize: 30, color: Color(0xFF6B6FAB))),
],
),
loginForm()
],
),
),
),
],
),
),
if (_isLoading)
const Opacity(
opacity: 0.8,
child: ModalBarrier(dismissible: false, color: Colors.black),
),
if (_isLoading)
const Center(
child: CircularProgressIndicator(color: Color(0xFFb1bbd8)),
),
],
);
Return a scaffold and add a sized box of height and width same as device. As a body use stack. Then in children add the next stack.
return Scaffold(
resizeToAvoidBottomInset: false,
body: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
background(),
SizedBox(
height:MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
mainAxisSize : MainAxisSize.min,
children:[
Padding(
padding: const EdgeInsets.only(top: 55),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/logo.png', height: 100),
const SizedBox(width: 5),
const Text('GLOBE',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Color(0xFF7FCCDC)))
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 100, left: 35, right: 35, bottom: 50),
child: Container(
decoration: BoxDecoration(
color: const Color(0xFFFCFBF4).withOpacity(0.5),
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('Welcome!',
style: TextStyle(
fontSize: 30, color: Color(0xFF6B6FAB))),
],
),
loginForm()
],
),
),
),
]
)
)
if (_isLoading)
const Opacity(
opacity: 0.8,
child: ModalBarrier(dismissible: false, color: Colors.black),
),
if (_isLoading)
const Center(
child: CircularProgressIndicator(color: Color(0xFFb1bbd8)),
),
]
)
)
)
TextField has a property called scrollPadding.
scrollPadding: EdgeInsets.only(bottom: 40)
By default it is set to EdgeInsets.all(20.0)

Display list of datas from sharedprefrence to text widget flutter?

I am saving some list of data to Sharedprefrence and tried to call the data from saved sharedprefrence and it returs all the values i have saved,then i tried to show data from sharedprefrence to a text widget but it shows null,
i need something like,if i have t text widgets how do pass data to those two widget let's say ₹575 and TWA Cap
Retrieving the data from sharedprfrence
List<String> listdata=[];
void initState() {
super.initState();
SharedPrefrence().getCartItem().then((data) async{
listdata = data;
print(listdata);
});
}
this what i am geting from the sharedprefrence
[TWA Cap, ₹575, M, Red]
trying to shows te data to text widget (Whole widget)
Widget CoupensLists() {
return SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Container(
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Row(
children: <Widget>[
Expanded(
child: Card(
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: GestureDetector(
onTap: () {
},
child: Container(
height: 150,
width: 350,
child: Row(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.symmetric(vertical: 5),
child: Container(
height: 50,
width: 80,
child: Image.network("image"),
/* decoration: BoxDecoration(
image: DecorationImage(
image: Image.,
fit: BoxFit.fill,
),
),*/
),
),
SizedBox(
height: 5,
),
Text(
"Prodcut name",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
Text("Prodcut name",
style: TextStyle(fontSize: 12)),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
vertical: 4),
child: Container(
width: 80,
child: Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/bg_price_btn_black.svg',
),
Padding(
padding: const EdgeInsets.all(5),
child: Text(
"Price"
style: TextStyle(
color: Colors.white,
fontSize: 12),
),
)
],
),
),
),
Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/bg_boon_btn_red.svg',
),
Padding(
padding: const EdgeInsets.all(5),
child: Text(
"Book Now",
style: TextStyle(
color: Colors.white,
fontSize: 12),
),
)
],
),
],
),
],
),
],
),
),
),
),
),
],
);
},
),
),
);
}
Try this:
List<String> listdata=[];
void initState() {
super.initState();
SharedPrefrence().getCartItem().then((data) async{
setState(() {
listdata = data;
});
});
}
You're getting this because you didn't upated your screen after changing the listdata variable
use in initail function
setState(() {
listdata = data;
});
then
Widget CoupensLists() {
return SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Container(
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Row(
children: <Widget>[
Expanded(
child: Card(
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: GestureDetector(
onTap: () {
},
child: Container(
height: 150,
width: 350,
child: Row(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.symmetric(vertical: 5),
child: Container(
height: 50,
width: 80,
child: Image.network("image"),
/* decoration: BoxDecoration(
image: DecorationImage(
image: Image.,
fit: BoxFit.fill,
),
),*/
),
),
SizedBox(
height: 5,
),
Text(
listdata.length!=0? listdata[0]:"",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
Text( listdata.length!=0? listdata[1]:"",
style: TextStyle(fontSize: 12)),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
vertical: 4),
child: Container(
width: 80,
child: Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/bg_price_btn_black.svg',
),
Padding(
padding: const EdgeInsets.all(5),
child: Text(
listdata.length!=0? listdata[2]:"",
style: TextStyle(
color: Colors.white,
fontSize: 12),
),
)
],
),
),
),
Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/bg_boon_btn_red.svg',
),
Padding(
padding: const EdgeInsets.all(5),
child: Text(
listdata.length!=0? listdata[3]:"",
style: TextStyle(
color: Colors.white,
fontSize: 12),
),
)
],
),
],
),
],
),
],
),
),
),
),
),
],
);
},
),``
),
);
}

how can i use SingleChildScrollView in my code flutter?

hello My code for a page is like this. i need to scroll part below appbar.
_sheetController =
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
return
DecoratedBox(
decoration: BoxDecoration(color: Theme.of(context).canvasColor),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0), topRight: Radius.circular(40.0)),
child:
Container(
child:
ListView(
children: <Widget>[
Container(
child: Stack(
children: <Widget>[
Positioned(
left: 10,
top: 10,
child: IconButton(
onPressed: () {
_loading = false;
Navigator.of(context).pop();
},
icon: Icon(
Icons.close,
size: 30.0,
color: Theme.of(context).primaryColor,
),
),
)
],
),
height: 50,
width: 50,
),
Form(
key: _formKey,
autovalidate: _autoValidate,
child:SingleChildScrollView(child:
Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 140,
child: Stack(
children: <Widget>[
Positioned(
child: Align(
child: Container(
width: 130,
height: 130,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).primaryColor),
),
alignment: Alignment.center,
),
),
Positioned(
child: Container(
child: AutoSizeText(
"LOGIN",
maxLines: 1,
minFontSize:
MediaQuery.of(context).size.width/10.0,
maxFontSize:
MediaQuery.of(context).size.width/5.0,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
alignment: Alignment.center,
),
),
],
),
),
Padding(
padding: EdgeInsets.only(bottom: 20, top: 60),
child: CustomTextField(
onSaved: (input) {
_Email = input;
},
keyboardType: TextInputType.emailAddress,
validator: emailValidator,
icon: Icon(Icons.email),
hint: "EMAIL",
)),
CustomTextField(
icon: Icon(Icons.lock),
obsecure: true,
onSaved: (input) => _Password = input,
validator: (input) =>
input.isEmpty ? "*Required" : null,
hint: "PASSWORD",
),
Padding(
padding: EdgeInsets.only(right:
MediaQuery.of(context).size.width/1.96),
child: Container(
width: MediaQuery.of(context).size.width/2.310160428,
height: 40.0,
child:
FlatButton(
onPressed: resetSheet,
child: AutoSizeText("FORGOT PASWORD !" ,maxFontSize:
20.0,minFontSize: 10.0,maxLines: 1,),
),
)
),
SizedBox(
height: 10,
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
bottom: MediaQuery.of(context).viewInsets.bottom),
child: _loading == true
? CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Theme.of(context).primaryColor),
)
: Container(
child: filledButton(
"LOGIN",
Colors.white,
Theme.of(context).primaryColor,
Theme.of(context).primaryColor,
Colors.white,
_validateLoginInput),
height: 50,
width: MediaQuery.of(context).size.width,
),
),
SizedBox(
height: 20,
),
],
),
),
),
],
),
height: MediaQuery.of(context).size.height / 1.1,
width: MediaQuery.of(context).size.width,
color: Colors.white,
),
),
);
});
My code for a page is like this. i need to scroll part below appbar.
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(... ),
body: new Stack(
children: <Widget>[
new Container(
decoration: BoxDecoration(
image: DecorationImage(...),
new Column(children: [
new Container(...),
new Container(...... ),
new Padding(
child: SizedBox(
child: RaisedButton(..),
),
new Divider(),
new Column(
children: <Widget>[
new Container(
child: new Row(
children: <Widget>[
new Expanded(
child: new Text( ),
),
new IconButton(
icon: IconButton(..),
onPressed: () {
_changed(true, "type");
},
),
],
),
),
visibilityPropertyType
? new Container(
margin: EdgeInsets.all(24.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Expanded(... ),
new RaisedButton(..)
],
),
new Padding(
padding: const EdgeInsets.only(top: 10.0),
child: new Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Column(
children: <Widget>[
new Row(
children: <Widget>[.. ]),
new Row(
children: <Widget>[]),
new Row(
children: <Widget>[]),
new Row(
children: <Widget>[],
),
new Column(
children: <Widget>[
new Row(
children: <Widget>[],
),
],
),
],
),
),
],
))
: new Container(),
],
),
new Divider(
color: Colors.white,
)
])
],
),
);
}
I need to make body part scrollable. How can i implement that scroll.
I think the SingleChildScrollView must work here but doesn't may i have issues in my code i try for alot times to find error but don't any help ?