Extend the background image to the app bar Flutter app - flutter

I am wondering how I can extend the background image to the app bar. Right now the background photo stops close to the app bar and the app bar is transparent.
appBar: new AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
iconTheme: new IconThemeData(color: Color(0xFF18D191)),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/surf.jpg'),
fit: BoxFit.cover,
),
),```

Remove the AppBar from appBar parameter of scaffold.
Wrap the body of the scaffold with Stack and place the same AppBar at the bottom
body:Stack(
children:<Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/surf.jpg'),
fit: BoxFit.cover,
),
),
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child:AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
iconTheme: new IconThemeData(color: Color(0xFF18D191)),
)
)
]
)

Unfortunately, I am not able to do it :(
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
iconTheme: new IconThemeData(color: Color(0xFF18D191)),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/surf.jpg'),
fit: BoxFit.cover,
),
),
child: Container(
width: double.infinity,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new StakedIcons(),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 80.0),
child: new Text(
"Surf Spots",
style: new TextStyle(fontSize: 30.0),
),
),
],
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
child: new TextField(
decoration: new InputDecoration(labelText: 'Email'),
),
),
new SizedBox(
height: 25.0,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
child: new TextField(
obscureText: true,
decoration: new InputDecoration(labelText: 'Password'),
),
),
new Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 5.0, top: 10.0),
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) => HomePage ()
));
},
child: new Container(
alignment: Alignment.center,
height: 60.0,
decoration: new BoxDecoration(
color: Color(0xFF18D191),
borderRadius: new BorderRadius.circular(10.0)),
child: new Text("Login",
style: new TextStyle(
fontSize: 20.0, color: Colors.white)),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 10.0, right: 10.0, top: 10.0),
child: new Container(
alignment: Alignment.center,
height: 60.0,
child: new Text("Forgot Password",
style: new TextStyle(
fontSize: 17.0, color: Color(0xFF18D191))),
),
),
)
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 50.0),
child: new Text("Create a New Account", style: new TextStyle(
fontSize: 17.0, color: Color(0xFF18D191), fontWeight: FontWeight.bold)),
),
],
),
),
],
),
),
),
);
}
}```

Related

Flutter CustomScrollView „stick“ card on top

I want to create a list in Flutter with a small preview of the content before the user sees all information on a new screen.
Therefor I build a simple list with Sliver-Cards:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cards'),
backgroundColor: Colors.blue,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: CustomScrollView(
shrinkWrap: false,
slivers: <Widget>[
_buildHeader(),
_buildCard('1', Colors.white, Colors.red, Colors.transparent),
_buildCard('2', Colors.white, Colors.blue, Colors.red),
_buildCard('3', Colors.white, Colors.green, Colors.blue),
…
],
),
),
);
}
Widget _buildHeader() => SliverStickyHeader(
header: Container(
height: 50,
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.topLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Center(
child: Text(
"Card-Header",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
),
),
);
Widget _buildCard(
String logo, Color logoColor, Color cardColor, Color prevColor) =>
SliverStickyHeader(
header: GestureDetector(
child: Stack(
children: <Widget>[
Container(
height: 16,
color: prevColor,
),
Container(
height: 60,
decoration: BoxDecoration(
color: cardColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16))),
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.bottomLeft,
child: Text(
logo,
style:
TextStyle(color: logoColor, fontWeight: FontWeight.bold),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
color: cardColor,
),
),
);
Here’s a Screenshot:
The only thing missing is the method to show a small preview of the content, which I want to stick to the top of the list. For example, anything like in this GitHub post: https://github.com/loopeer/CardStackView/blob/master/screenshot/screenshot1.gif
Is it possible to create a method like this in flutter?

automatic height of the container in the flutter

I wrote a page, at the top everything is fine, as it should be. And at the bottom I have a history of events. The width of my container is determined automatically (depending on the width of the screen), and the height - no, on different devices different heights (indents at the bottom are different). Is it possible to determine the height automatically (to the end of the screen) ?? Also, I'd like to add a scroll bar at the bottom for this container so that when events appear there, I can scroll through them both bottom and top. I will be grateful for your help.
My page:
My code:
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
color:Colors.white12
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
textColor: Colors.blueGrey,
color: Colors.transparent,
child: Text('yes',textScaleFactor: 2.5),
onPressed: null,
padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
),
FlatButton(
textColor: Colors.blueGrey,
color: Colors.transparent,
child: Text('no',textScaleFactor: 2.5),
onPressed: null,
padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
)
],
),
SizedBox(height: 15.0),
Container(
child: Text(('20000' == null ? '' : '10000'), style: TextStyle(fontSize: 45.0,color: Colors.blueGrey)),
padding: EdgeInsets.fromLTRB(0, 0.0, 0, 20.0),
),
Container(
child: Text("weight", style: TextStyle(fontSize: 20.0,color: Colors.blueGrey)),
padding: EdgeInsets.only(top: 2, bottom:40, left:0, right:0),
),
Center(
child: Container(
alignment: Alignment.center,
width: double.infinity,
height: 430,
decoration: BoxDecoration(
border: Border.all(
width: 1.5
),
borderRadius: BorderRadius.circular(25)
),
child: new Column(
children: [
Container(
child: Text("history events", style: TextStyle(fontSize: 20.0,color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)
),
],
),
)//Container
)
]
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_scanQR();
});
},
child: const Icon(Icons.qr_code),
backgroundColor: Colors.pink,
),
);
}
My scrin (after updating the code)
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: <Widget>[
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
textColor: Colors.blueGrey,
color: Colors.transparent,
child: Text('yes', textScaleFactor: 2.5),
onPressed: null,
padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
),
FlatButton(
textColor: Colors.blueGrey,
color: Colors.transparent,
child: Text('no', textScaleFactor: 2.5),
onPressed: null,
padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
)
],
),
SizedBox(height: 15.0),
Container(
child: Text(('20000' == null ? '' : '10000'), style: TextStyle(fontSize: 45.0, color: Colors.blueGrey)),
padding: EdgeInsets.fromLTRB(0, 0.0, 0, 20.0),
),
Container(
child: Text("weight", style: TextStyle(fontSize: 20.0, color: Colors.blueGrey)),
padding: EdgeInsets.only(top: 2, bottom: 40, left: 0, right: 0),
),
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(7, 0, 7, 7),
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(border: Border.all(width: 1.5), borderRadius: BorderRadius.circular(25)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 45,
child: Text("history events", style: TextStyle(fontSize: 25.0, color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)),
Expanded(
child: Scrollbar(
child: new ListView(
shrinkWrap: true,
children: [
Container(
child: Text("Event 1", style: TextStyle(fontSize: 50.0, color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)),
SizedBox(
height: 200,
),
Container(
child: Text("Event 2", style: TextStyle(fontSize: 50.0, color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)),
SizedBox(
height: 200,
),
Container(
child: Text("Event 3", style: TextStyle(fontSize: 50.0, color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)),
SizedBox(
height: 50,
),
],
))),
],
))))
]),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
// _scanQR();
});
},
child: const Icon(Icons.qr_code),
backgroundColor: Colors.pink,
),
);
}
You can alter the responsive height or width by using Media Query .To do that you need to wrap your Scaffold with Material App or Cupetino App which allows you to use MediaQuery .
void main() {
runApp(MaterialApp(home: MyApp()));
}
To make the list scrollable simply you can use ListView.builder
Center(
child: Container(
margin: new EdgeInsets.only(bottom: 20,right: 15,left: 15),
alignment: Alignment.center,
width: double.infinity,
height: MediaQuery.of(context).size.height/1.5,
decoration: BoxDecoration(
border: Border.all(width: 1.5),
borderRadius: BorderRadius.circular(25)),
child: new Column(
children: [
Container(
child: Text("history events",
style: TextStyle(
fontSize: 20.0, color: Colors.blueGrey)),
padding: EdgeInsets.all(2.0)),
],
),
) //Container
)
I added a little margin to make it looks better.Ofcourse you can also use MediaQuery for margin or padding if you want to.
https://i.stack.imgur.com/W6oXd.png

Cupertino Sliverapp bar not scrolling

Hello guys i am working in this Platform specific flutter application and wanted have sliver like the gif listed bellow i was able to achieve part of it but the search bar is not moving with scrolling.Please help.
Widget _buildContent(context, productBloc, isIOS) {
return CustomScrollView(slivers: <Widget>\[
CupertinoSliverNavigationBar(
border: null,
backgroundColor: Colors.grey\[50\],
leading: Padding(
padding: const EdgeInsets.only(bottom: 16, left: 10),
child: Transform.scale(
scale: 4.5,
child: Image.asset('assets/images/whitelogo.png'),
),
),
largeTitle: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: \[
SizedBox(
width: MediaQuery.of(context).size.width * 0.75,
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: CupertinoTextField(
placeholderStyle: TextStyle(color: Colors.grey\[300\]),
placeholder: 'Enter Product Name',
prefix: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
FrinoIcons.f_search_2,
size: 20,
),
),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey\[300\]),
borderRadius: BorderRadius.circular(5),
color: Colors.white,
),
),
),
),
\],
),
trailing: GestureDetector(
child: const Icon(
FrinoIcons.f_cart,
color: const Color(0xFFf79B34),
size: 28,
),
onTap: () => Navigator.of(context).pushNamed('/cart'),
),
)]
Try replacing CustomScrollView with NestedScrollView:
Widget _buildContent(context, productBloc, isIOS) {
return NestedScrollView(slivers: <Widget>\[
CupertinoSliverNavigationBar(
border: null,
backgroundColor: Colors.grey\[50\],
leading: Padding(
padding: const EdgeInsets.only(bottom: 16, left: 10),
child: Transform.scale(
scale: 4.5,
child: Image.asset('assets/images/whitelogo.png'),
),
),
}
}

set an widget alignment in flutter

Hello everyone i want to use a bottom navigator in product details file but I have two containers inside my row widget. I want to set my first container(which is Old Price and New Price Column) at the left, and also want to set my second container(which is Add to cart btn) at the right. how can I achieve this?
Here is code:
bottomNavigationBar: Material(
elevation: 7.0,
color: Colors.white,
child: Container(
height: 60.0,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Container(
height: 40.0,
width: MediaQuery.of(context).size.width - 280.0,
decoration: BoxDecoration(
color: Color(0xfff40725),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'Add to cart',
style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.bold),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left:8.0),
child: Container(
child: Column(
children: <Widget>[
Text("\$${widget.prod_old_price}",textAlign: TextAlign.left,style: TextStyle(fontSize: 18.0,color: Color(0xff989898),decoration: TextDecoration.lineThrough),),
Text("\$${widget.prod_price}",style: TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold)),
],
),
),
),
],
),
),
),
Try this :
bottomNavigationBar: Material(
elevation: 7.0,
color: Colors.white,
child: Container(
height: 60.0,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Container(
height: 40.0,
width: MediaQuery.of(context).size.width - 280.0,
decoration: BoxDecoration(
color: Color(0xfff40725),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'Add to cart',
style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.bold),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left:8.0),
child: Container(
child: Column(
children: <Widget>[
Text("\$${widget.prod_old_price}",textAlign: TextAlign.left,style: TextStyle(fontSize: 18.0,color: Color(0xff989898),decoration: TextDecoration.lineThrough),),
Text("\$${widget.prod_price}",style: TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold)),
],
),
),
),
],
),
),
),
Set proper mainAxisAlignment in the Row. You can refer this
I would have set it to mainAxisAlignment: MainAxisAlignment.spaceAround

Flutter appbar left actions

I am trying to align the Top AppBar Actions to the left but I failed
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0.0,
elevation: 5.0,
backgroundColor: Color(0xff201F23),
title: Icon(
Icons.polymer,
color: Colors.orange,
size: 30.0,
),
actions: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(0, 8, 10, 8),
child: CircleAvatar(
backgroundImage: ExactAssetImage('assets/Bronze.jpg'),
),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.orange,
width: 1.0,
),
borderRadius: new BorderRadius.all(new Radius.circular(50.0)),
)),
Container(
//margin: EdgeInsets.fromLTRB(0, 0, 130, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Ov3rControl',
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(height: 4.0),
Row(
children: <Widget>[
Icon(
Icons.trip_origin,
color: Colors.orange,
size: 12.0,
),
SizedBox(width: 4.0),
Text('1000', style: TextStyle(fontSize: 12.0))
],
),
]),
)
],
),
drawer: Drawer());
}
I want the items to be next to the Logo. how can I achieve that?
I Tried putting left margin to the container but the design break when the name of the user gets bigger
Also, I am new to flutter is there is any way to make this code better?
Is this what you are looking for?
Find the changes in the code below:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0.0,
elevation: 5.0,
backgroundColor: Color(0xff201F23),
title: Row(
children: <Widget>[
Icon(
Icons.polymer,
color: Colors.orange,
size: 30.0,
),
SizedBox(width: 15,),
Container(
margin: EdgeInsets.fromLTRB(0, 8, 10, 8),
child: CircleAvatar(
backgroundImage: ExactAssetImage('assets/Bronze.jpg'),
),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.orange,
width: 1.0,
),
borderRadius: new BorderRadius.all(new Radius.circular(50.0)),
)),
Container(
//margin: EdgeInsets.fromLTRB(0, 0, 130, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Ov3rControl',
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(height: 4.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
Icons.trip_origin,
color: Colors.orange,
size: 12.0,
),
SizedBox(width: 4.0),
Text('1000', style: TextStyle(fontSize: 12.0))
],
),
]
),
)
],
),
),
drawer: Drawer()
);
}
You can also use the leading property in the AppBar and pass your widget to it
leading: IconButton(
icon: Icon(Icons.shopping_cart),
tooltip: 'Open shopping cart',
onPressed: () {
// handle the press
},
),