extendBody: true, property moves - flutter

I am trying to recreate the main page of Spotify. At first I wasn't able to make my navigation bar transparent then I learned that I should use extendBody: true property. It worked and I got a transparent navigation bar but now it seems like it changed the space between the items on the screen and I am clueless at this point. This is the part where I added extendBody property:
#override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
appBar: AppBar(
backgroundColor: Color(0xFF212121),
title: Text("Spotify", style: TextStyle(fontFamily: 'Work Sans', fontWeight: FontWeight.bold)),
elevation: 0,
actions: [
IconButton(onPressed: (){}, icon: Icon(Icons.notifications_outlined)),
IconButton(onPressed: (){}, icon: Icon(Icons.history)),
IconButton(onPressed: (){}, icon: Icon(Icons.settings)),
],
),
And this is the part that forms gridlist and the problematic part:
FutureBuilder<List<GridListe>>(
future: gridListeyiGetir(),
builder: (context, snapshot){
if(snapshot.hasData){
var gridListe = snapshot.data;
return Padding(
padding: const EdgeInsets.only(top: 15),
child: GridView.builder(
shrinkWrap: true,
itemCount: gridListe!.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 3/1),
itemBuilder: (context, index){
var list = gridListe[index];
return Card(
semanticContainer: true,
color: Color(0xFF535353),
child: Row(
children: [
Image.asset("resimler/${list.listeResmi}", fit: BoxFit.fitHeight),
Padding(
padding: const EdgeInsets.only(left: 5),
child: Text(list.listeAdi, style:TextStyle(color: Colors.white,fontFamily: 'Work Sans' ,fontWeight: FontWeight.bold) , ),
),
],
),
);
}
),
);
}else{
return const Center();
}
},
),
Padding(
padding: const EdgeInsets.only(right: 280),
child: const Text("Made For You", style: TextStyle(color: Colors.white, fontFamily: 'Work Sans',fontWeight: FontWeight.bold, fontSize: 15)),
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: SizedBox(
height: 180,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
SizedBox(
width: 160,
child: Card(
elevation: 0,
color: Color(0xFF212121),
child:
Column(mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("resimler/dailymix1.jpg"),
Text("Daily Mix 1", style: TextStyle(color: Colors.white, fontFamily: "Work Sans", fontWeight: FontWeight.bold), ),
],
),
),
),
As can be seen in the images the grid list and "Made For You" text should be somewhat close to eachother however its not the case.
when extendBody:false
when extendBody:true

Related

How I put Blur image in the scaffold background in flutter

I want to put the transparent image on the background with text on it. I tried with container in return but it's not working. Also I tried container in the body, but unfortunately that is also not working for me. It's a single screen app. Below is my code. Your answer will be very helpful for me.
Thanks in advance.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/tree.png",
),
),
centerTitle: true,
title: Text(
"Welcome To Plants",
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w800,
),
)),
body: Column(
children: [
Flexible(
child: ListView.builder(
itemCount: _messages.length,
reverse: true,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(8.0), child: _messages[index]),
),
),
const Divider(
color: Color.fromARGB(255, 51, 223, 56),
thickness: 1,
),
_istyping ? LinearProgressIndicator() : Container(),
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _controller,
onSubmitted: (value) => _sendMessage(),
decoration: const InputDecoration.collapsed(
hintText: "Type Here",
hintStyle: TextStyle(fontSize: 20)),
),
)),
ButtonBar(children: [
IconButton(
onPressed: () {
_isImageSearch = false;
_sendMessage();
},
icon: Icon(
Icons.send,
color: Theme.of(context).primaryColor,
)),
TextButton(
onPressed: () {
_isImageSearch = true;
_sendMessage();
},
child: Text("Show Image"))
]),
],
),
)
],
)
Import the following module
import 'dart:ui';
make sure you included the asset in your yaml file
eg: used lib/utils/images/test.jpg
Example Scaffold
Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: <Widget>[
Image.asset('lib/utils/images/test.jpg', fit: BoxFit.fill),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Container(
color: Colors.black.withOpacity(0.5),
),
),
// Add your UI component here
],
),
);
Example screenshot

Flutter ListView grouped

How can I achieve something like this
https://i.stack.imgur.com/XShsq.png
So far I handle to get this
https://i.stack.imgur.com/GIs0d.png
But I dont know how to separate each container
this is my actual code
Widget build(BuildContext context) {
TextStyle boldStyle = const TextStyle(fontWeight: FontWeight.bold);
return BlocConsumer<AppCubit, AppState>(
listener: (context, state) {},
builder: (context, state) {
List<PurchaseCategory> purchases =
AppCubit.get(context).purchasesCategories;
return Container(
decoration: buildBoxDecoration(context),
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
child: GroupedListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
elements: purchases,
groupBy: (PurchaseCategory purchase) => purchase.date,
groupHeaderBuilder: (PurchaseCategory purchase) => Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'${purchase.date}',
style: boldStyle,
),
Text(
'Total: 400 \$',
style: boldStyle,
),
],
),
const Divider(
color: Colors.red,
),
],
),
),
itemBuilder: (BuildContext context, PurchaseCategory purchase) {
return ListTile(
contentPadding: const EdgeInsets.all(0),
leading: Container(
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: purchase.categoryColor,
),
child: Icon(purchase.categoryIcon),
),
title: Text(
purchase.description,
style: boldStyle,
),
subtitle: Text(purchase.categoryName),
trailing: Text(
'\$ ${purchase.price}',
style: boldStyle,
),
);
},
),
);
},
);
}
I handle to grouped by dates but I would like to grouped in different containers as the first picture

How to make fixed button flutter?

I have a problem with fixed button inside scroll view , I made a column with SingleChildScrollView and two button, but the problem is that the screen do not scroll. I tried the bottom Navigation bar but it has the same problem. How I can fix this?
my code :
Column(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
ListView.builder(
shrinkWrap: true,
itemCount: 200,
itemBuilder: (context, index) {
return Text("200");
},
),
ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context, index) {
return Text("bargougui");
},
),
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.grey[300],
),
onPressed: () {},
child: Text(
'Contacter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.yellow,
),
onPressed: () {},
child: Text(
'Acheter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
],
),
],
),
screen I want to make like this
any help will be appreciated ^^
Use Stack widget,
Stack(
children:[
SingleChildScrollView(),
Positioned(
bottom:0,
left:15,
right:15,
child:Row(children :[Button1(),Button2()],
,)
]
Try tweaking the numbers to fit your case.

How do I call the ListView using CustomScrollView and display all the elements?

I have a ListView that is seperated by a divider and is called as shown below.
I have called all the elements however the last tile gets cut on my screen. I've tried adding the SliverPadding around the List but it doesn't help and crops the list even more.
This is the code for my ListView:
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 80.0),
child: CustomScrollView(slivers: <Widget>[
SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.09,
bottom: MediaQuery.of(context).size.height * 0.015,
left: 18.0),
child: Text("Puppies",
style: khomeStyle.copyWith(color: kOrange, fontSize: 27)),
),
),
SliverFillRemaining(
child: ListView.separated(
itemCount: 10,
//shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
//padding: EdgeInsets.all(0),
separatorBuilder: (BuildContext context, int index) {
return Divider();
},
itemBuilder: (BuildContext context, int index) {
return ListTile(
isThreeLine: false,
leading: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Container(
child: Image.network(
'https://www.thesprucepets.com/thmb/LhWrTxh5MaOb_6IY-fgLxH75SI8=/2121x1193/smart/filters:no_upscale()/golden-retriever-puppy-in-grass-923135452-5c19243546e0fb000190737c.jpg'),
),
),
title: Row(
children: <Widget>[
Text(
"Helllo",
style: khomeStyle.copyWith(
fontSize: 17,
color: kOrange,
fontWeight: FontWeight.w600),
),
],
),
subtitle: Text(
'This is a message',
style: khomeStyle.copyWith(
fontSize: 15,
color: Colors.black.withOpacity(0.7),
fontWeight: FontWeight.w300),
));
}),
),
]),
),
],
),
);
}
This is what the ListView looks like:
https://i.stack.imgur.com/vyL2x.png
If you are not looking for Slivers, try below code. this will scroll till last item and nothing will be cropped.
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.only(top: 80.0),
child: SingleChildScrollView(
child: ListView.separated(
itemCount: 10,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return Divider();
},
itemBuilder: (BuildContext context, int index) {
return ListTile(
isThreeLine: false,
leading: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Container(
child: Image.network(
'https://www.thesprucepets.com/thmb/LhWrTxh5MaOb_6IY-fgLxH75SI8=/2121x1193/smart/filters:no_upscale()/golden-retriever-puppy-in-grass-923135452-5c19243546e0fb000190737c.jpg'),
),
),
title: Row(
children: <Widget>[
Text(
"Helllo",
style: khomeStyle.copyWith(
fontSize: 17,
color: kOrange,
fontWeight: FontWeight.w600),
),
],
),
subtitle: Text(
'This is a message',
style: khomeStyle.copyWith(
fontSize: 15,
color: Colors.black.withOpacity(0.7),
fontWeight: FontWeight.w300),
));
}),
),
),
);
}

Change size of Card in Drawer

I need to change the size of the cards so they are longer vertically.
child:Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Text('DRAWER HEADER',
style: TextStyle(color: Colors.white),),
decoration: BoxDecoration(color:Colors.deepPurple.shade300),
),
Card(
color: Colors.deepPurple.shade300,
child: ListTile(
title: Text('Hi',
style: TextStyle(color: Colors.white),),
onTap:(){debugPrint('Add');},
)
),
),
You can achieve that goal in many ways:
You can add Padding inside your Text
Containers have a height parameter
or you could use SizedBox and then your Card inside, like this:
int listLength = 8; // The size of your List, this will vary.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Drawer + Card"),
),
drawer: Drawer(
child: ListView.builder(
itemCount: listLength + 1, // + 1 is to handle your Header
itemBuilder: (context, index) {
return index == 0
? SizedBox(
height: 160,
child: Container(
margin: EdgeInsets.only(bottom: 10),
color: Colors.deepPurple.shade300,
child: Padding(
padding: const EdgeInsets.all(10),
child: Text(
"DRAWER HEADER",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w600),
),
),
),
)
: SizedBox(
height: 80, // Change this size to make it bigger or smaller
child: Card(
color: Colors.deepPurple.shade300,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
"Index $index",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
),
),
);
},
),
),
),
);
}
The end result is what you're looking for: