how can put image inside the image in flutter - dart

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

Related

Adding a new column to a card in Flutter

How do I add a new column to a Card in flutter?
Currently, I have 2 Columns and can't figure out how to add a third between these since they are on the left and right sides. When I have tried adding a "new Column", it only creates a new row of text under the first Column.
This is my code so far:
Widget _buildListItem(BuildContext context, Record record) {
return Card(
key: ValueKey(record.activityName),
elevation: 8.0,
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
child: ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
title: Text(
record.activityName,
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 23),
),
subtitle: Row(
children: <Widget>[
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
text: TextSpan(
text: "Activations: "+record.activations+
"\n"+record.dateCompleted,
style: TextStyle(color: Colors.white),
),
maxLines: 2,
softWrap: true,
)
],
)
)
],
),
trailing: Container(
child: Hero(
tag: "avatar_" + record.activityName,
child: CircleAvatar(
radius: 32,
backgroundImage: NetworkImage(record.icon),
backgroundColor: Colors.white,
)
)
),
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => new DetailPage(record: record)));
}
),
)
);
}
I am wanting 3 columns so that I can add either an image in the middle of this card.
Current output
Expected output
Based on your screenshot, here is the solution. You can modify it according to your needs.
Widget _buildListItem(BuildContext context) {
return Card(
margin: EdgeInsets.all(12),
elevation: 4,
color: Color.fromRGBO(64, 75, 96, .9),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16),
child: Row(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Jumping", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 4),
Text("Activations 9", style: TextStyle(color: Colors.white70)),
Text("03-08-19", style: TextStyle(color: Colors.white70)),
],
),
Spacer(),
CircleAvatar(backgroundColor: Colors.white),
],
),
),
);
}
Output:

giving widgets a specific place in all screens

i have just started learning how to develop apps in flutter...
but i have something to ask about:
am trying to place some widgets at specific place of the screen in all screens..
for example here's my code:
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
child: Column(
children: [
Container(
padding: EdgeInsets.only(top: 50.0),
child: new Image.asset(
'assets/images/walk1ar.png',
fit: BoxFit.cover,
height: 30.0,
width: 169.0,
alignment: Alignment.center,
),
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 30.0, bottom: 5.0),
child: new Image.asset(
'assets/images/walkside.png',
fit: BoxFit.cover,
height: 445.0,
width: 14.0,
alignment: Alignment.centerRight,
),
),
Container(
padding: EdgeInsets.only(
top: 30.0, bottom: 5.0, left: 50.0, right: 50.0),
child: new Image.asset(
'assets/images/walkpic1.png',
fit: BoxFit.cover,
height: 445.0,
width: 250.0,
alignment: Alignment.center,
),
),
Container(
padding: EdgeInsets.only(top: 30.0, bottom: 5.0),
child: new Image.asset(
'assets/images/walkside.png',
fit: BoxFit.cover,
height: 445.0,
width: 14.0,
alignment: Alignment.centerLeft,
),
),
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: Text(
'اهلاً وسهلاً',
style:
new TextStyle(fontSize: 20.0, color: Color(0xFF49C275)),
)),
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(bottom: 5.0),
child: Text(
'أهلا وسهلا بكم في معرض وظائف ٢٠١٨',
style:
new TextStyle(fontSize: 14.0, color: Color(0xFF707070)),
)),
],
),
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
child: new RaisedButton(
child: const Text(
'إبدأ',
),
color: Color(0xFF49C275),
elevation: 71.0,
splashColor: Colors.blueGrey,
onPressed: () {
// Perform some action
},
),
)
],
),
],
)),
);
}
here i want the last widget which is the button to be at the bottom of the screen always ... also the walkside image .. i want one to stick to the right side of the screen and the other to the left always..
how to do so?
You can use stack and align your button to the end of the screen. Here is an example:
Stack(
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: width,
height: 40.0,
child: RaisedButton(
color: azulClaro,
child: Text(
'My Button',
style: TextStyle(
color: Colors.white,
),
),
),
),
),
],
);

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.

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

How to overlay a view partially using the Stack widget in Flutter

I am using Flutter for my app development.
I would like to overlay a poster image view on top of a background image just like in this screenshot below.
The code snippet below does this, but it requires me to also position every other widget including the movie title, release date, etc based on poster's position and background image's position, which is not reliable across several devices and orientation. Is there an example or suggestion to solve this problem?
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new PlatformAdaptiveAppBar(
title: new Text(widget.movie.title),
),
body: new Container(
constraints: new BoxConstraints.expand(),
child: new Stack(
children: <Widget>[
new Container(
child: new Image(
image: new AdvancedNetworkImage(
movieGridUtil.getUrlFromPath(widget.movie.backdrop_path,
MovieGridImageTypes.BACKDROP),
useMemoryCache: false,
useDiskCache: true)),
constraints: new BoxConstraints.expand(height: 250.0),
),
new Positioned(
left: 12.0,
top: 220.0,
child: new Image(
width: 100.0,
height: 150.0,
image: new AdvancedNetworkImage(
movieGridUtil.getUrlFromPath(widget.movie.poster_path,
MovieGridImageTypes.POSTER),
useMemoryCache: false,
useDiskCache: true),
)),
],
)),
);
}
Create Stack
Then inside Stack add Column and make full layout without the poster.
Then as a second Child of Stack, add this combination:
new Stack(
children: [
new Column(
children: _layout()
new Positioned(
top:200,
left:50,
child: _child // or optionaly wrap the child in FractionalTranslation
)]
)
)
Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 200.0,
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0, top:160.0),
child: Container(
color: Colors.pink,
height: 150.0,
width: 110.0,
),
)
],
),
By Creating the Stack,
You can add multiple Container, whichever is last added will be on the top.
Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 200.0,
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0, top:160.0),
child: Container(
color: Colors.pink,
height: 150.0,
width: 110.0,
),
)
],
),

Resources