Blur image with text overlaid in flutter - flutter

I need to blur the pictures in the background, and make the text clear overlay, but for some reason the text is also blurry, and, as I have the GridView in two columns, then the last image in the second column is correct, with clear text, but all the rest are incorrect.
Expanded(
child: SmartRefresher(
enablePullDown: true,
header: WaterDropHeader(),
controller: _refreshController,
onRefresh: _refreshNews,
child: GridView.count(
crossAxisCount: 2,
childAspectRatio: 1.5,
crossAxisSpacing: 1.5,
mainAxisSpacing: 1,
padding:
EdgeInsets.only(left: 1, top: 0, right: 1, bottom: 60),
children: List.generate(
items.length,
(index) =>
Stack(
children: [
ClipRRect(
child:
Image.network(items[index].get_photoUrl),
borderRadius: BorderRadius.circular(30),
),
BackdropFilter(
filter: prefix0.ImageFilter.blur(
sigmaY: 1,
sigmaX: 1,
),
child: Container(
color: Colors.black.withOpacity(0)),
),
Center(
child: Text(
items[index].get_title,
style: prefix1.TextStyle(
fontSize: 12, color: Colors.white),
),
)
],
)
),
)))

1.you can use Stack to show picture and text in the same container.
e.g -> new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: new Container(
decoration: new BoxDecoration(color:
Colors.white.withOpacity(0.0)),
),
)
Full example ->
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new ExactAssetImage('assets/dog.png'),
// NetworkImage("url")
fit: BoxFit.cover,
),
),
child: new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: new Container(
decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
),
),
),
Text("hello flutter ")
],
),
),
);
}
try this
Happy Coding :))

Result:
Expanded(
child: SmartRefresher(
enablePullDown: true,
header: WaterDropHeader(),
controller: _refreshController,
onRefresh: _refreshNews,
child: GridView.count(
crossAxisCount: 2,
childAspectRatio: 1.5,
crossAxisSpacing: 1.5,
mainAxisSpacing: 1,
padding:
EdgeInsets.only(left: 1, top: 0, right: 1, bottom: 60),
children: List.generate(
items.length,
(index) => Stack(
children: <Widget>[
ClipRRect(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image:
NetworkImage(items[index].get_photoUrl),
),
),
child: new BackdropFilter(
filter: new ImageFilter.blur(
sigmaX: 1.5, sigmaY: 1.5),
child: Container(
color: Colors.white.withOpacity(0.0)),
),
),
borderRadius: BorderRadius.circular(30),
),
Center(child: Text(items[index].get_title))
],
),
),
)))

Related

Add a text widget at the bottom of every grid view item in flutter

I am new to flutter and I am making a shop app.
In the homescreen I have used grid view builder to display images of items. Now I want to add two text widgets at the bottom of each grid view item which shows the item name and price of the item.
This gridview builder is a child of a column widget. The column widget has two text widgets and gridview builder as its child.
GridView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: loadedProducts.length,
itemBuilder: (ctx, i) => Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: secondaryColorlight,
borderRadius: BorderRadius.circular(defaultBorderRadius)),
child:
Image.asset(
loadedProducts[i].imageUrl,
height: 132,
),
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
)
This is how my homepage looks right now
This is how I want it to look
You can return Column from itemBuilder. You may also need to increase height from childAspectRatio
itemBuilder: (ctx, i) => Column(
children: [
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: secondaryColorlight,
borderRadius: BorderRadius.circular(defaultBorderRadius)),
child: Image.asset(
loadedProducts[i].imageUrl,
height: 132,
),
),
// padding if needed
Text("your text"),
],
),
Also you can check GridTile widget.
More about layout in flutter
GridView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: loadedProducts.length,
itemBuilder: (ctx, i) => Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: secondaryColorlight,
borderRadius: BorderRadius.circular(defaultBorderRadius)),
child:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Container(
height: 190.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child:Image.asset('images/image.png'),
),
),
),
SizedBox(height: 5.0),
Padding(
padding: const EdgeInsets.only(left: 10.0, bottom: 5.0, right: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text('Price'),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text('Sometext'
maxLines: 1,
overflow: TextOverflow.ellipsis, ),
],
),
Text('title',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
)

how to remove the gridView extra space it give between widgets - Flutter

i am working on this flutter app where i need to show the children in a grid view, so i used a column widget in side GridView.builder like shown below, i want to remove the sapcing where its marked in the red, and leave it to be responsive somehow...
GridView widget:
GridView.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
crossAxisSpacing: 10,
mainAxisSpacing: 10,
maxCrossAxisExtent: 450,
),
primary: false,
shrinkWrap: true,
padding: const EdgeInsets.only(
right: 25,
left: 25,
top: 20,
),
itemCount: data.length,
itemBuilder: (ctx, index) {
return VideoWidget(
oneVideoData: data[index],
);
},
),
VideoWidget:
Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: double.infinity,
decoration: BoxDecoration(
...
),
child: Row(
children: [
...
],
),
),
Stack(
alignment: AlignmentDirectional.center,
children: [
_videoPlayerControllerFFrame.value.isInitialized
? AspectRatio(
aspectRatio:
_videoPlayerControllerFFrame.value.aspectRatio,
child: VideoPlayer(
_videoPlayerControllerFFrame,
),
)
: Container(
height: 250,
),
_isVideoLoading
? const CircularProgressIndicator(
color: Colors.yellow,
)
: IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return VideoPlayerWidget(
oneVideoData: widget.oneVideoData,
videoController: _videoPlayerController,
);
});
},
icon: Icon(
Icons.play_arrow,
color: Theme.of(context).colorScheme.tertiary,
size: 50,
),
),
],
),
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 10,
),
...
),
),
],
),
);
this a screen shot of the output:
i want to get rid of the red space in the bottom.
Thanks in advance
Try below code hope its help to you.
GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: 6,
itemBuilder: (BuildContext context, int index) {
return Card(
elevation: 5,
shadowColor: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10,
),
),
margin: EdgeInsets.all(5),
child: Container(
height: 200,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(2),
child: Row(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.black,
width: 1.0,
),
),
child: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
),
),
),
SizedBox(
width: 10,
),
Text('Person ${index.toString()}'),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
),
),
),
),
),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
),
child: Text(
'Awesome Product From Person ${index.toString()}',
),
),
],
),
),
);
},
),
Result Screen->

Flutter: How to implement State Management onPressed

I have no idea how to change the state of my grid view when a button is clicked can someone help me with this?
So, I have this textButton that should change the state of my grid view when clicked but I have no idea how to implement it. Below is my code.
From the image attached, when water, food, school etc are clicked the gridview should only provide specific organizations..
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
padding: const EdgeInsets.only(left: 20, right: 20),
height: SizeConfig.screenHeight / 6.5,
color: kPrimaryColor,
child: Row(
children: [
const CircleAvatar(
radius: 40,
backgroundImage: AssetImage(
'assets/images/SDG Wheel_Transparent_WEB.png'),
),
const SizedBox(
width: 10,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Donate Today!",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontFamily: "Quicksand",
decoration: TextDecoration.none),
),
SizedBox(
height: 5,
),
Text(
"Small contributions quickly\nadd up if enough people\ntake up the cause.",
style: TextStyle(
color: Colors.white,
fontSize: 12,
decoration: TextDecoration.none),
),
],
),
Expanded(child: Container()),
Container(
width: 70,
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xFFf3fafc)),
child: Center(
child: IconButton(
icon: SvgPicture.asset("assets/icons/give.svg"),
onPressed: () {},
color: Color(0xFF69c5df),
//size: 30,
),
),
),
],
),
),
),
SizedBox(
height: 30,
),
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Select your desired organisation to donate.",
style: TextStyle(
color: Color(0xFF1f2326),
fontSize: 15,
decoration: TextDecoration.none),
),
),
const Divider(color: Colors.black38),
//here is the textButton
Container(
height: 50,
width: double.infinity,
color: Colors.white,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < categories.length; i++)
Container(
width: 90,
padding: const EdgeInsets.only(left: 4.0, right: 4.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: kPrimaryColor,
),
child: TextButton(
onPressed: () {}, //here i need a way to change the state of
the grid view
child: Text(categories[i],
style: TextStyle(color: Colors.white)),
),
),
),
],
),
),
),
const Divider(color: Colors.black38),
const SizedBox(
height: 30,
),
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: _listItem
.map((item) => Card(
color: Colors.transparent,
elevation: 0,
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, item.route),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(item.image),
fit: BoxFit.cover)),
)),
))
.toList(),
)
],
),
);
}
}
Thanks very much.
The simplest things to do is to Filter your items based on selection by using the .where of Iterable https://api.flutter.dev/flutter/dart-core/Iterable/where.html
Basically when you push your Text button you store the type in a variable (you need a StatefulWidget for that)
then you can use where to filter your _listItem
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: _listItem
.where((element) {
//if your element is included return true else false
return true;
})
.map((item) => Card(
color: Colors.transparent,
elevation: 0,
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, item.route),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(item.image),
fit: BoxFit.cover)),
)),
))
.toList(),
)
You can check a sample here for the behavior on the button:
https://dartpad.dev/49f2e4818d933c75a0e6ed1d47a836d2

How can I implement this card view design in Flutter

I want the second column of cards to be slightly uneven how can I achieve that.
here is the output that I want:
You can use GridView.builder like this
GridView.builder(
padding: EdgeInsets.only(left: 20, right: 20),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 20,
mainAxisSpacing: 8,
childAspectRatio: 0.7,
),
itemCount: 10,
itemBuilder: (context, index) {
return Padding(
padding: (index % 2) == 0 ? EdgeInsets.only(bottom: 15) : EdgeInsets.only(top: 15),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Container(
decoration: BoxDecoration(
color: (index % 2) == 0 ? Colors.red : Colors.green,
borderRadius: BorderRadius.circular(10),
),
),
),
);
},
);
One approach would be to add two columns inside a row:
Row(
children: [
Expanded(
child: Column(
children: [
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
],
),
),
Expanded(
child: Column(
children: [
const SizedBox(
height: 50,
),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
CardWidget(/*...*/),
],
),
),
],
);

space between items in gridview flutter

I have a gridview with 6 items (cards with images and text). I want those 6 items to fit me on the screen but the gridview leaves all the space I can between items by jumping 2 items off the screen.
I leave a picture of what I want and what I have.
Thank you.
return MaterialApp(
home: Scaffold(
body: Container(
margin: EdgeInsets.only(top: 0),
child: Stack(
alignment: AlignmentDirectional.topCenter,
children: <Widget>[
Container(
height: 200,
color: Colors.black,
),
Container(
margin: EdgeInsets.only(top: 200),
decoration: BoxDecoration(
image: new DecorationImage(
image: AssetImage("assets/fondo.png"), fit: BoxFit.fill)),
),
Image.asset("assets/cara_simio_banner.png"),
Padding(
padding: EdgeInsets.only(top: 220),
child: Text(
"{CodeJaVu}",
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
),
),
Container(
margin: EdgeInsets.only(top: 230),
child: GridView.count(
crossAxisCount: 2,
children: items.map((item) {
return GestureDetector(
onTap: () {},
child: CardItem(item),
);
}).toList(),
),
)
],
),
)));
}
Widget CardItem(Item item) {
return Card(
margin: EdgeInsets.all(40),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child:
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset(
item.image,
width: 50,
height: 50,
),
Text(item.name)
],
)
);
}
class Item {
String _name;
String _image;
Item(this._name, this._image);
String get name => _name;
set name(String name) => _name = name;
String get image => _image;
set image(String image) => _image = image;
}
what I have,
what I want,
add childAspectRatio parametr to GridView.cout counstructor,
and change Card margin.
I've used:
..
GridView.count(
childAspectRatio: 3/2,
..
Card(
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
..
You can also use mainAxisSpacing and crossAxisSpacing like below.
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisSpacing: 8, mainAxisSpacing: 4),
padding: EdgeInsets.all(8),
shrinkWrap: true,
itemCount: widgetList.length,
itemBuilder: (context, index) {
return widgetList[index];
},
);
Just add these 2 lines in your GridView widgets:
mainAxisSpacing: 20,
crossAxisSpacing: 20,
children:
space.photos.map((item) {
return Container(
margin: EdgeInsets.only(
left: 24,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Image.network(
item,
width: 110,
height: 88,
fit: BoxFit.cover,
),
),
);
}).toList()