EDIT
Its cutting off my background gradient and not showing the image.
I need to have a layout in flutter with a column of text objects to the left and an image to the right. I found an example picture on the flutter.io site but they dont show the code for this particular example. I have the column of data formatted but cant figure out how to add the image to the right.
Here is the picture of what I am trying to get layout wise.
Here is my existing code with the data we want to the right of the image
class MemberProfile extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: LBAppBar().getAppBar(),
drawer: LBDrawer().getDrawer(),
body:
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color.fromRGBO(1, 89, 99, 1.0), Colors.grey],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
),
child:
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Name : Sam Cromer",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Sex : Male",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Age : 42",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Status : Divorced",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Trumatic Event : ",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Motorcycle Accident July 2005, TBI",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0),
child: Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(
left: 30.0, top: 150.0, bottom: 30.0, right: 30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.all(20.0),
child: OutlineButton(
child: Text('Offer support'),
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
onPressed: () {
// Navigator.of(context).push( MaterialPageRoute(builder: (BuildContext context) => CheckInQ()));
},
),
)
],
),
)
],
),
),
//here
),
);
}
}
This is the your MemberProfile class modified to contain one custom row laid out as the above image:
class MemberProfile extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color.fromRGBO(1, 89, 99, 1.0), Colors.grey],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
),
width: MediaQuery.of(context).size.width,
height: 200.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget> [
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Name : Sam Cromer",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Sex : Male",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Age : 42",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Status : Divorced",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Trumatic Event : ",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Motorcycle ",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
],
),
Column(
children: <Widget>[
SizedBox(
width: 200.0,
height: 200.0,
child: Image.asset('assets/images/test.jpg'), // Your image widget here
),
],
),
]
),
),
);
}
}
the code given here limits the height of the row to 200.0 so the size of the image doesn't distort the total layout of the row , you can opt for an alternative approach by placing the Image widget into a SizedBox with fixed width and height.
The reason the gradient was cut off is because it's applied in the parent Container and containers by definition "size themselves to the size of their children", so if you want your "gradient effect" to fill the full screen you have to set an explicit width and height:
body:
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
import 'package:flutter/material.dart';
class MemberProfile extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color.fromRGBO(1, 89, 99, 1.0), Colors.grey],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
),
width: MediaQuery.of(context).size.width,
//height: 1500.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget> [
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text("Name : Sam Cromer",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Sex : Male",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Age : 42",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Status : Divorced",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Event : Motorcycle",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
],
),
Column(
children: <Widget>[
SizedBox(
width: 200.0,
height: 200.0,
child: Image.asset('lib/img/darth-vader_small.jpg'), // Your image widget here
),
],
),
]
),
),
);
}
}
Related
I'm developing a login page and splash screen for a certain application, how can I set those route to launch only once?
Stack(
fit: StackFit.loose,
children: <Widget>[
Image(
image: AssetImage('images/home.png'),
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// SizedBox(height: 20.0),
//height was 60
Column(
children: <Widget>[
SizedBox(
height: 30.0,
),
Text(
"SMART HYDROPONICS",
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 30.0,
),
CircleAvatar(
backgroundColor: Colors.white,
radius: 90.0,
child: Container(
alignment: Alignment.center,
child: CircleAvatar(
backgroundColor: Colors.green,
child: Text(
'REGISTER',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
radius: 70.0,
),
)),
],
),
SizedBox(height: 20.0),
Form(
key: _key,
autovalidate: _autovalidate,
child: Column(children: <Widget>[
TextFormField(
decoration: InputDecoration(
hintText: "Enter Name",
border: InputBorder.none,
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.nature_people,
size: 30.0,
color: Colors.black,
)),
maxLength: 25,
keyboardType: TextInputType.text,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_name = val;
},
validator: _myName,
),
SizedBox(
height: 20.0,
),
SizedBox(height: 40.0),
TextFormField(
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: "Enter Number",
border: InputBorder.none,
// contentPadding: EdgeInsets.all(0.0),
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.phone,
size: 30.0,
color: Colors.black,
)),
maxLength: 10,
maxLines: 1,
keyboardType: TextInputType.phone,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_number = val;
},
validator: _myNumber,
),
SizedBox(
height: 50.0,
),
TextFormField(
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: "Product ID",
border: InputBorder.none,
// contentPadding: EdgeInsets.all(0.0),
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.settings_brightness,
size: 30.0,
color: Colors.black,
)),
maxLength: 10,
maxLines: 1,
keyboardType: TextInputType.phone,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_number = val;
},
validator: _productId,
),
// SizedBox(height: MediaQuery.of(context).size.height/990000 ),
RaisedButton(
onPressed: _sendToServer,
color: Colors.greenAccent,
child: Text(
"Finish",
style: TextStyle(
color: Colors.white,
),
)),
]),
),
]),
],
)
You'll want to keep persistent state (like login tokens or flags marking things as viewed/accepted) via the shared_preferences plugin or some other persistent store that's local like sqlite or a flat file.
I want to use Appbar with text "Back" button I a using below code but
"Back" is coming in two line like below, also Appbar title is moving down side.
Ba
ck
Flutter code for same
final topAppBar = AppBar(
// elevation: 0.1,
backgroundColor: Color.fromRGBO(0, 113, 188, 1.0),
title: Text(
"MyAppBar",
style: TextStyle(
color: Colors.white,
fontFamily: 'Raleway-ExtraBold',
fontWeight: FontWeight.w900,
fontSize: 20.0,
),
),
leading: Padding(
padding: const EdgeInsets.only(left: 0),
child: FlatButton(
child: Text(
"Back",
// textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontFamily: "Raleway-Medium",
fontSize: 14.0,
),
),
),
),
);
Is there any thing which I am missing here??
Use - FittedBox - fit: property to adjust leading widget.
leading: FittedBox(
fit: BoxFit.cover,
child: FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, // add this to remove padding.
onPressed: () {},
child: Text(
"Back",
// textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontFamily: "Raleway-Medium",
fontSize: 14.0,
),
),
),
),
Use leadingWidth with enough width.
leadingWidth: 80,
leading: Padding(
padding: const EdgeInsets.only(left: 0),
child: FlatButton(
child: Text(
"Back",
// textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontFamily: "Raleway-Medium",
fontSize: 14.0,
),
),
),
Below are my code I always got some pixel overflowed on right size. I was playing with Expanded and Fixable widgets as well as mainAxisSize of row and column too.
Look at the code:
Widget productDisplayListView(List<Products> listOfProduct, int index) {
return Container(
margin: EdgeInsets.all(7),
child: Container(
child: Card(
elevation: 4,
child: Container(
padding: EdgeInsets.all(6),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
height: 110,
width: 90,
child: Image.network(
listOfProduct[index].thumbnail ?? '',
fit: BoxFit.cover,
),
),
Container(
padding: EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
height: 20,
width: 20,
child: Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
SizedBox(height: 5),
Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
SizedBox(height: 5),
Text(
'₹${listOfProduct[index].price ?? ''}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],
),
)
],
),
),
),
),
);
}
I tried with many Que./Ans. on stackOverFlow but But didn't get success.
Updated Code with Fixed Overflow Error. Have to made quite a change in your Widget Tree.
Widget productDisplayListView() {
return Card(
elevation: 4,
child: Container(
padding: EdgeInsets.all(6),
child: Row(
children: <Widget>[
Container(
height: 110,
width: 90,
child: Image.network(
'https://placeimg.com/250/250/any',
fit: BoxFit.cover,
),
),
SizedBox(
width: 5.0,
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MergeSemantics(
child: Row(
children: <Widget>[
Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
),
SizedBox(height: 5),
Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
SizedBox(height: 5),
Text(
'₹ 10,000',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],
),
)
],
),
),
);
}
OutPut:
Check Your Rows Add Column Widgets. If any row or column widget has a single flexible child an error will occur
Doing like this should fix your problem:-
..... Container(
padding: EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
height: 20,
width: 20,
child: Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
),
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
SizedBox(height: 5),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
),
SizedBox(height: 5),
Text(
'₹${listOfProduct[index].price ?? ''}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],
I have a list of containers wrapped in a listview, I need to give a onTap functionality like when the user taps on the container it should give me a value of that particular container, below is my code and I tried using Inkwell function but it throws an error saying vertical portview. Help me out and thanks in advance.
dynamic _allVehiclesDataView = new ListView(
children: List.generate(this._allVehiclesData.length,
(i) => new Container(
decoration: new BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey[300]),
),
),
padding: const EdgeInsets.all(32.0),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom:5.0),
child: Text(
this._allVehiclesData[i]["vehicle"]["registration"],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Text(
'Location :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey,
),
),
Text(
(this._allVehiclesData[i]["address"] == null ||
this._allVehiclesData[i]["address"] == 'Not determined') ?
"No data available" : ""+this._allVehiclesData[i]["address"]["LongLabel"],
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Last known update :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
Text(
(this._allVehiclesData[i]["deviceTime"]),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
this._allVehiclesData[i]["fuel"] != "null"?
new Row(
children: <Widget>[
Text(
'Fuel Level :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
new Container(
decoration: new BoxDecoration(
shape : BoxShape.circle,
border: new Border.all(
color: Colors.blue[300],
width: 5.0,
)
),
),
Text(
(this._allVehiclesData[i]["fuel"].toString()),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
],
) : Text(''),
this._allVehiclesData[i]["temperature"] != "null" ?
new Row(
children: <Widget>[
Text(
'Temp :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
new Container(
decoration: new BoxDecoration(
shape : BoxShape.circle,
border: new Border.all(
color: Colors.red[300],
width: 5.0,
)
),
),
Text(
(' '+this._allVehiclesData[i]["temperature"].toString()+' C'),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
],
):Text(""),
],
),
),
status(i),
// new InkWell(),
],
),
),
),
);
You can use the GestureDetector for the same
Wrap your Container in a GestureDetector with an onTap callback
GestureDetector(
// When the child is tapped, do your work
onTap: () {
...
...
},
// Container
child: Container(
...
),
);
I am trying to build my own card within flutter however I keep getting the error of child not being defined.
The type of card I am trying to build can be seen here
Is it also possible to link me to a tutorial that properly explains when to use child and children as this seems to be my issue at this time.
My code can be seen below:
List<Widget> cardlist = <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Row(
child: new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
)
],
child: new Row(
child: new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
child: new Text(
'News Location',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
child: new Image.asset(
'images/lake.jpg',
height: 240.0,
fit: BoxFit.cover,
),
child: new Text(
'News Headline',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
child: new Text(
'News Summary',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
child: new Row(
child: new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
child: new Text(
'News Source',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
child: new Text(
'12 hours ago',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
)
];
I think you want something like what I have below, not sure it is exactly right but it should give you a starting point. Basically you need to understand when to use child and when children, and the correct syntax. just think about the widget you are using and if it could contain one (child) or more than one (children) child widgets, or look at the docs to see what it takes :)
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Card(
child: new Column(
children: [
new Row(
children: [
new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
]
),
]
),
),
new Card(
child : new Row(
children : [
new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
new Text(
'News Location',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
]
),
),
new Card(
child: new Column(
children: [
new Image.asset(
'images/lake.jpg',
height: 240.0,
fit: BoxFit.cover,
),
new Text(
'News Headline',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
new Text(
'News Summary',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
new Row(
children : [
new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
new Text(
'News Source',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
new Text(
'12 hours ago',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
]
),
]
),
),
],
),
),