How to create flutter list linear gradien widget? [closed] - dart

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I make a widget like in the image
and how to control the degree
The shape 2

This will generate UI as you required
Widget build(BuildContext context) {
return new Container(
height: 100.0,
margin: new EdgeInsets.all(10.0),
decoration: new BoxDecoration(borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
gradient: new LinearGradient(colors: [Colors.yellow[700], Colors.redAccent],
begin: Alignment.centerLeft, end: Alignment.centerRight, tileMode: TileMode.clamp)),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Padding(padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new Icon(Icons.cloud, color: Colors.white70,),
),
new Expanded(child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text('New York', style: new TextStyle(fontSize: 20.0, color: Colors.white70, fontWeight: FontWeight.bold),),
new SizedBox(height: 8.0,),
new Text('Sunny', style: new TextStyle(fontSize: 12.0, color: Colors.white70),),
],)),
new Padding(padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new Text('12°', style: new TextStyle(fontSize: 30.0, color: Colors.white70),),)
],),
);
}

If you are looking for linear gradient then you can use LinearGradient in Container.
new Container(
child: new Text('Hello'),
decoration: new BoxDecoration(
gradient: new LinearGradient( // <-- This is what you need to do
colors: [
Colors.red[200],
Colors.red
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: new BorderRadius.all(
new Radius.circular(10.0)
)
),
padding: new EdgeInsets.all(20.0),
margin: new EdgeInsets.all(20.0),
)
If you wish to have custom design boxes Container is what you'll need.
NOTE: Always check the docs first. https://docs.flutter.io

Related

how can put image inside the image in flutter

https://i.stack.imgur.com/w5mLQ.png
Like what we see a small circular image inside the big picture . And how to arrange the text as in the picture
https://i.stack.imgur.com/w5mLQ.png
Widget build(BuildContext context) {
return new Container(
height: 150.0,
margin: new EdgeInsets.all(10.0),
decoration: new BoxDecoration(borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
gradient: new LinearGradient(colors: [Colors.yellow[700], Colors.redAccent],
begin: Alignment.centerLeft, end: Alignment.centerRight, tileMode: TileMode.clamp)),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Padding(padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new CircleAvatar(radius: 35.0, backgroundImage: NetworkImage('https://wallpapercave.com/wp/wp2365076.jpg'),)
),
new Expanded(child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text('New York', style: new TextStyle(fontSize: 20.0, color: Colors.white70, fontWeight: FontWeight.bold),),
new SizedBox(height: 8.0,),
new Text('Sunny', style: new TextStyle(fontSize: 12.0, color: Colors.white70),),
new SizedBox(height: 10.0,),
new Row(children: <Widget>[
new Column(children: <Widget>[
new Text('2342', style: new TextStyle(fontSize: 12.0, color: Colors.white)),
new Text('Popularity', style: new TextStyle(fontSize: 10.0, color: Colors.white)),
],),
new Column(children: <Widget>[
new Text('2342', style: new TextStyle(fontSize: 12.0, color: Colors.white)),
new Text('Like', style: new TextStyle(fontSize: 10.0, color: Colors.white)),
],),
new Column(children: <Widget>[
new Text('2342', style: new TextStyle(fontSize: 12.0, color: Colors.white)),
new Text('Followed', style: new TextStyle(fontSize: 10.0, color: Colors.white)),
],)
],)
],)),
new Padding(padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('12°', style: new TextStyle(fontSize: 30.0, color: Colors.white70),),
new Text('Ranking', style: new TextStyle(fontSize: 14.0, color: Colors.white70),),
],))
],),
);
}
It will take a few widgets to accomplish what you would like to achieve. Here is how I would solve it (it might need some fine tuning to fit your exact needs, but should get you started):
First start with the background (I believe you call it the big picture). To accomplish this you could use the Container widget to draw the rectangle and use set the decoration property with a BoxDecoration widget to set the background image.
Next set the child property of the Container widget with a Row widget which will contain the circular image and a Column widget to contain the text elements.
The whole thing could look something like this:
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets/images/card_background.png'),
fit: BoxFit.cover,
),
),
child: new Row(
children: <Widget>[
new CircleAvatar(
backgroundImage: new AssetImage('assets/images/avatar.png')
),
new Column(
children: <Widget>[
new Text('David Borg'),
new Text('Title: Flying Wing'),
],
),
],
),
)
Here are some references to the most important widgets used in the above code snippet:
Container widget
BoxDecoration widget
CircleAvatar widget
Column widget
Row widget
Note that I have not tested the code listed in the snippet so it might need a little bit of tweaking.
Have a look at this example (a hamburger icon and three red points over a purple clipped background):
If you would like to have this, the code would be pretty short:
body: Column(
children: <Widget>[
ClipPath(
clipper: MyClipper(),
child: Container(
height: 350,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Color.fromRGBO(16, 27, 117, 0.5),
Color.fromRGBO(16, 27, 117, 0.5),
]),
image: DecorationImage(
image: AssetImage(
"assets/images/points_removed.png",
),
),
),
child: Align(
alignment: Alignment(-0.8, -0.6),
child: Image.asset(
"assets/images/hamburger_icon.png",
width: 30,
height: 20,
),
),
),
),
],
),
(optional) the code for clipping the background
class MyClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
var path = Path();
path.lineTo(0, size.height - 80);
path.quadraticBezierTo(
size.width / 2, size.height, size.width, size.height - 80);
path.lineTo(size.width, 0);
path.close();
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}

how can make like this widget or card list flutter

how can make like this widget
or card list
[![enter image description here][2]][2]
This will generate your required UI decorate it as per your requirement
Widget build(BuildContext context) {
return new Container(
alignment: Alignment.centerLeft,
margin: new EdgeInsets.all(8.0),
padding: new EdgeInsets.all(8.0),
height: 150.0,
decoration: new BoxDecoration(
color: Colors.lightBlue,
borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
boxShadow: [new BoxShadow(color: Colors.black54, offset: new Offset(2.0, 2.0),
blurRadius: 5.0)]
),
child: new Row(children: <Widget>[
new CircleAvatar(backgroundColor: Colors.white70,radius: 50.0,),
new Expanded(child: new Padding(padding: new EdgeInsets.only(left: 8.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text('Hot Pot', style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),),
new Row(children: <Widget>[
new Icon(Icons.star, color: Colors.white,),
new Icon(Icons.star, color: Colors.white,),
new Icon(Icons.star, color: Colors.white,),
new Icon(Icons.star_half, color: Colors.white,),
new Icon(Icons.star_border, color: Colors.white,),
],),
new Wrap(spacing: 2.0,children: <Widget>[
new Chip(label: new Text('Hot')),
new Chip(label: new Text('Hot')),
new Chip(label: new Text('Hot')),
],)
],),))
],),
);
}
Take a look at this question.
For the background image, use a Container with a BoxDecoration. For the image on the left use the Image.asset widget.

flutter all widgets on screen hides when keyboard appears

I am using TabBar and a custom searchview, when I click inside TextField to search and keyboard pops up my all view hides, am attaching screenshots below. Is this flutter issue or I am doing wrong in my code. Please have a look at my code. without popping up keyboard my this is working fine.
return new Scaffold(
body: new Container(
// margin: EdgeInsets.all(10.0),
//color: Colors.white30,
child: new Column(
children: <Widget>[
new Container(
height: 70.0,
color: Theme.of(context).primaryColor,
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Card(
child: new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 3.0),
child: new Icon(Icons.search),
),
new Container(
width: MediaQuery.of(context).size.width - 100.0,
// Subtract sums of paddings and margins from actual width
child: new TextField(
controller: controller,
decoration: new InputDecoration(
hintText: 'Search', border: InputBorder.none),
// onChanged: onSearchTextChanged,
),
),
new IconButton(icon: new Icon(Icons.cancel), onPressed: () {
controller.clear();
// onSearchTextChanged('');
FocusScope.of(context).requestFocus(new FocusNode());
},),
],
),
)
))),
new Flexible(
child: new ListView.builder(
itemCount: productList == null ? 0 : productList.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Column(
children: <Widget>[
new Container(
margin: EdgeInsets.all(10.0),
child: new Column(
children: <Widget>[
new Column(
children: <Widget>[
new Padding(padding: const EdgeInsets.only(top: 5.0)),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Container(
alignment: FractionalOffset.topLeft ,
width: 250.0,
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Text(productList[index].name,
style: new TextStyle(color: Colors.black,
fontSize: 18.0, fontWeight: FontWeight.bold),
)
],
),
),
new Text("£"+productList[index].price.toString(),
style: new TextStyle(color: Colors.black,
fontSize: 18.0, fontWeight: FontWeight.bold
),),
],
)
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start ,
children: <Widget>[
new Text(
productList[index].description,
overflow: TextOverflow.fade ,),
],
))
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new ListTileItemAddRemove(productList[index]),
new Padding(padding: EdgeInsets.only(bottom: 10.0))
],
)
],
),
),
new Divider(color: Colors.black,)
],
),
);
}),
),
],
)
),
);
when I click inside TextField all widgets disappears. please see below.
I think flutter widgets are resized when keyboard pops up, I've resolved this issue by setting value false of resizeToAvoidBottomPadding inside Scaffold. Issue has been resolved but still I am looking for the reason behind this issue.
return new Scaffold(
resizeToAvoidBottomPadding : false,
body: new Container(
-
-
-
-
}

Flutter align widgets in an expanded container, to the top left and bottom right?

I have a layout in my application which comprises of some text and a timestamp. I'm looking to have the timestamp (clock icon in the picture) be at the bottom left corner of the expanded widget, while the text ("what" string in the picture) should start from the top right.
Representation:
|text| |
| ----------- |
| empty space |
| ----------- |
| |time|
Currently, what I managed below have them aligned to the extreme left and right, but they seem to be constrained by the Column widget and as such, are aligned to the centre of the widget. And I cannot seem to get expanded to work within another Expanded.
Widget code:
return new Container(
child: new Row(
children: <Widget>[
new Column(
children: <Widget>[
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.keyboard_arrow_up),
onPressed: () => null,
),
new Container(
padding: new EdgeInsets.all(5.0),
child: new Text("1231"),
),
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.keyboard_arrow_down),
onPressed: () => null,
),
],
),
new Expanded(
// child: new Container(
// padding: EdgeInsets.all(10.0),
child: new Column(
// mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.topLeft,
child: new Text("what"),
),
// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."),
new Align(
// padding: new EdgeInsets.all(10.0),
alignment: Alignment.bottomRight,
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Container(
padding: new EdgeInsets.all(2.0),
child: new Icon(
Icons.access_time,
size: 12.0,
),
),
new Container(
padding: new EdgeInsets.all(2.0),
child: new Text("1 hr"),
),
],
),
),
],
),
// ),
),
new Column(
children: <Widget>[
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.save, size: 20.0),
onPressed: () => null,
),
new Container(
padding: new EdgeInsets.all(5.0),
child: new Text("8"),
),
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.comment, size: 20.0),
onPressed: () => null,
),
],
),
],
),
);
}
try using alignment: Alignment.bottomRight as a named parameter of Container class
Ok, so I modified your Widget and I added some Colors to the container to track the changes very easy:
double maxHeight = 130.0;
Widget _buildLeft() {
return Container(
height: maxHeight,
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.keyboard_arrow_up),
onPressed: () => null,
),
new Container(
padding: new EdgeInsets.all(5.0),
child: new Text("1231"),
),
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.keyboard_arrow_down),
onPressed: () => null,
),
],
),
);
}
Widget _buildCenter() {
return Expanded(
child: Container(
height: maxHeight,
color: Colors.blue,
child: Stack(
children: <Widget>[
Positioned(
child: new Text("what"),
top: 0.0,
left: 0.0,
),
// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."),
Positioned(
bottom: 0.0,
right: 0.0,
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Container(
padding: new EdgeInsets.all(2.0),
child: new Icon(
Icons.access_time,
size: 12.0,
),
),
new Container(
padding: new EdgeInsets.all(2.0),
child: new Text("1 hr"),
),
],
),
),
],
),
),
);
}
Widget _buildRight() {
return Container(
height: maxHeight,
color: Colors.green,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.save, size: 20.0),
onPressed: () => null,
),
new Container(
padding: new EdgeInsets.all(5.0),
child: new Text("8"),
),
new MaterialButton(
minWidth: 60.0,
child: new Icon(Icons.comment, size: 20.0),
onPressed: () => null,
),
],
),
);
}
#override
Widget build(BuildContext context) {
return new Container(
child: new Row(
children: <Widget>[
_buildLeft(),
_buildCenter(),
_buildRight(),
],
),
);
}
You can use a Container wrap the Align, This can stop Align from expanding itself
Container(
color: darkBlue,
child: Align(
alignment: Alignment.center,
heightFactor: value,
child: Container(
// alignment: Alignment.center, //<--must not uncomment this
padding: const EdgeInsets.all(16),
color: Colors.red,
child: child,
),
),
)

How do I absolutely position a badge in a BottomNavigationBarItem

I am using BottomNavigationBarItem to display bottom navigation UI with icons and text. I would like to be able to add badges with numeric values on those. Here is my current attempt:
bottomNavigationBar:
new BottomNavigationBar(items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
icon: new Stack(
children: <Widget>[
const Icon(Icons.home),
new Positioned(
top: 0.0,
left: 0.0,
child: new Container(
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(4.0),
color: Colors.red),
width: 16.0,
child: new Text(
"12",
style: const TextStyle(color: Colors.white),
),
))
],
),
title: new Text("Home")),
new BottomNavigationBarItem(
icon: const Icon(Icons.star), title: new Text("Star")),
],
type: BottomNavigationBarType.fixed),
However, the badge is positioned with the icon's bounding box, so it overlaps heavily with the icon:
What I would like, instead, is something like that:
Is it possible to achieve this using the BottomNavigationBarItem widget? If not, what would be a good workaround?
make sure that the badge position is right, and the overflowing children should be visible
icon: new Stack(
overflow: Overflow.visible,
children: <Widget>[
const Icon(Icons.home),
new Positioned(
top: -1.0,
right: -6.0,
child: new Container(
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(4.0), color: Colors.red),
width: 16.0,
child: new Text(
"12",
style: const TextStyle(color: Colors.white),
),
))
],
),
If it is useful to anyone, I made one that works in the AppBar.
static Widget makeIconWithBadge(String badgeText, GestureTapCallback onTap) {
return Container(
padding: EdgeInsets.only(right: 16.0),
child: Center(
child: new Stack(
overflow: Overflow.visible,
children: <Widget>[
const Icon(Icons.inbox),
new Positioned(
top: -6.0,
right: -6.0,
child: Container(
padding: EdgeInsets.all(2.0),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(99.0),
color: Colors.white,
),
child: new Container(
padding: EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(99.0),
color: Colors.red),
child: Center(
child: new Text(
"12",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 12.0,),
),
),
),
),
),
Positioned.fill(
child: Material(
borderRadius: BorderRadius.all(Radius.circular(99.0)),
color: Colors.transparent,
child: InkWell(onTap: onTap),
),
)
],
),
),
);
}

Resources