Flutter ListView grouped - flutter

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

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

How to set number of elements to show in a CarouselSlider per page, using carousel_slider in flutter

I'm creating a vertical carousel slider using carousel_slider but there's a huge empty space between elements and I can't display the previous element on the screen. What is the best way to remove the empty space and also show the previous element.
My screen is set as follows
Column(
children: [
Container(
margin: const EdgeInsets.fromLTRB(16, 16, 16, 16),
child: TextField(
controller: controller,
),
),
//Carousel built here
Expanded(
child: CarouselSlider.builder(
itemCount: cars.length,
itemBuilder: (context, index, pageViewIndex) => CarTile(
car: cars[index],
onpress: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CarDetailsScreen(car: cars[index]))),
),
options: CarouselOptions(
scrollDirection: Axis.vertical,
enlargeCenterPage: true,
),
),
),
],
);
CarTile code is as follows:
class CarTile extends StatelessWidget {
final Car car;
final VoidCallback onpress;
const CarTile({super.key, required this.onpress, required this.car});
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return GestureDetector(
onTap: onpress,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
child: Column(
children: [
Image.network(
height: 150,
width: size.width,
fit: BoxFit.fitWidth,
car.image,
),
const SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(5)),
child: Text(
car.features[0],
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
const SizedBox(
width: 5,
),
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(5)),
child: Text(
car.features[1],
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
],
),
),
Row(
children: [
Text(
'${car.brand} ${car.model}',
style: const TextStyle(fontWeight: FontWeight.w900),
),
const Spacer(),
Text(
'Tsh. ${NumberFormat.decimalPattern().format(car.price)} / hr',
style: const TextStyle(fontWeight: FontWeight.w900),
),
],
),
Align(alignment: Alignment.centerLeft, child: Text('${car.year}'))
],
),
),
);
}
}
And this is my current results

extendBody: true, property moves

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

onPageChanged with Future Dialog Flutter

I am trying to get my Flutter Dialog to show page indicator dots based off the onPageChanged setState and it doesnt seem to be working. What is happening is the dots are appearing and one is highlighted but as I swipe the dots are not following the current page. Any ideas? When I add a print statement to my setState I can see the activePage is corresponding with the current index. I am at odds as to why this is not working?
Future openDialog() => showDialog(
context: context,
builder: (BuildContext context) => Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
backgroundColor: const Color(0xFF64748b),
child: Container(
height: 300.0, // Change as per your requirement
width: 300.0, // Change as per your requirement
child: Column(
children: [
SizedBox(
width: MediaQuery.of(context).size.width,
height: 200,
child: PageView.builder(
scrollDirection: Axis.horizontal,
pageSnapping: true,
itemCount: eqs.length,
controller: _pageController,
onPageChanged: (page) {
setState(() {
activePage = page;
// print(activePage);
});
},
itemBuilder: (context, index) {
final titles = eqs[index];
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(15.0),
child: Text(
titles.eqTitle,
style: const TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Math.tex(
titles.eq,
mathStyle: MathStyle.display,
textStyle: const TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: indicators(eqs.length, activePage))
],
),
),
));
List<Widget> indicators(eqsLength, currentIndex) {
return List<Widget>.generate(eqsLength, (index) {
return Container(
margin: const EdgeInsets.all(5.0),
width: 10,
height: 10,
decoration: BoxDecoration(
color: currentIndex == index ? Colors.greenAccent : Colors.black26,
shape: BoxShape.circle),
);
});
}
Hey if you're trying to have a page indicator at the bottom of your page view, you can just use a very simple package called smooth_page_indicator
Future openDialog() => showDialog(
context: context,
builder: (BuildContext context) => Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
backgroundColor: const Color(0xFF64748b),
child: Container(
height: 300.0, // Change as per your requirement
width: 300.0, // Change as per your requirement
child: Column(
children: [
SizedBox(
width: MediaQuery.of(context).size.width,
height: 200,
child: PageView.builder(
scrollDirection: Axis.horizontal,
pageSnapping: true,
itemCount: eqs.length,
controller: _pageController,
itemBuilder: (context, index) {
final titles = eqs[index];
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(15.0),
child: Text(
titles.eqTitle,
style: const TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Math.tex(
titles.eq,
mathStyle: MathStyle.display,
textStyle: const TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
),
),
// Add this
SmoothPageIndicator(
controller: _pageController, // PageController
count: eqs.length,
effect: WormEffect(), // your preferred effect
onDotClicked: (index) {})
],
),
),
),
);
But if you want to have your custom widget for the indicator, instead of updating the active page, update your current index.
Hope you find this helpful!
[AMIR SMILEY]

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),
));
}),
),
),
);
}