Adding background in flutter dashboard - flutter

Please any expert who can suggest to me how to a background picture in this dashboard, I'll be very thankful.
When I add boxfit in the following scaffold widget the code got red lines.
Please any expert who can suggest to me how to a background picture in this dashboard, I'll be very thankful.
When I add boxfit in the following scaffold widget the code got red lines.
import 'package:google_fonts/google_fonts.dart';
import 'package:maps_app/screens/Dash_board.dart';
class Dashboard extends StatefulWidget {
static const routeName = '/home1';
#override
DashboardState createState() => new DashboardState();
}
class DashboardState extends State<Dashboard> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffffffff),
body: Column(
children: <Widget>[
SizedBox(
height: 110,
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"ColorLine",
style: GoogleFonts.openSans(
textStyle: TextStyle(
color: Colors.black87,
fontSize: 24,
fontWeight: FontWeight.bold)),
),
SizedBox(
height: 4,
),
Text(
" Home",
style: GoogleFonts.openSans(
textStyle: TextStyle(
color: Color(0xff000000),
fontSize: 14,
fontWeight: FontWeight.w600)),
),
],
),
IconButton(
iconSize: 70,
alignment: Alignment.center,
icon: Image.asset(
"assets/colorline.png",
width: 100,
height: 100,
),
onPressed: () {},
)
],
),
),
SizedBox(
height: 40,
),
GridDashboard()
],
),
);
}
}

Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpeg"),
fit: BoxFit.cover,
),
),
child: ...
),
);

What you want to do is wrap your Scaffold with a Container Widget. Also, you need to make the Scaffold's color transparent. I will be using a bit of Vlad Konoshenko's answer to help you with this.
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpeg"),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
// Rest of the code remains same.
...
),
);

Related

The widget is not appearing up - Flutter

I'm using AdvancedPageTurn widget from advanced_page_turn package. I wrapped this widget inside the Scaffold body property. The widget is appearing on the simulator perfectly, but when I launch the application on the real device, that particular AdvancedPageTurn widget is not appearing up at all.
What could be the problem?
class Lyrics extends StatefulWidget {
#override
_LyricsState createState() => _LyricsState();
}
class _LyricsState extends State<Lyrics> {
final _controller = GlobalKey<AdvancedPageTurnState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('App Title', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontFamily: 'oswald'),),
centerTitle: true,
flexibleSpace: Image(
image: AssetImage('images/bg.jpg'),
fit: BoxFit.cover,
),
),
body: SafeArea(child: AdvancedPageTurn( // The Widget content is not appearing up at all but working fine on emulator
key: _controller,
initialIndex: 0,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/bg.jpg'), fit: BoxFit.cover),
),
padding: EdgeInsets.all(25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Title 1', style: TextStyle(fontSize: 28.0, height: 1.8, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center,),
],
),
),
Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/bg.jpg'), fit: BoxFit.cover),
),
padding: EdgeInsets.all(25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Title 2', style: TextStyle(fontSize: 28.0, height: 1.8, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center,),
],
),
),
],
),
),
);
}
}

Scaffold body content is not appearing up - Flutter

I'm using an advanced page turn widget to show the flipping the effect between pages and it's working perfectly fine on an emulator but when I run the application on the real device, the body content is not appearing up at all (just showing a grey screen)
the page turn widget is wrapped inside the body, so I guess it has to do something with the widget
Note:- The body content is appearing up on an emulator
Package link https://pub.dev/packages/advanced_page_turn
Here is my code
class Lyrics extends StatefulWidget {
#override
_LyricsState createState() => _LyricsState();
}
class _LyricsState extends State<Lyrics> {
final _controller = GlobalKey<AdvancedPageTurnState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('App Title', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontFamily: 'oswald'),),
centerTitle: true,
flexibleSpace: Image(
image: AssetImage('images/bg.jpg'),
fit: BoxFit.cover,
),
),
backgroundColor: Colors.grey[200],
body: SafeArea(child: AdvancedPageTurn( // The body content is not appearing up at all but working fine on emulator
key: _controller,
initialIndex: 0,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/bg.jpg'), fit: BoxFit.cover),
),
padding: EdgeInsets.all(25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Title 1', style: TextStyle(fontSize: 28.0, height: 1.8, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center,),
],
),
),
Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/bg.jpg'), fit: BoxFit.cover),
),
padding: EdgeInsets.all(25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Title 2', style: TextStyle(fontSize: 28.0, height: 1.8, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center,),
],
),
),
],
),
),
);
}
}

Adding an image background to home page

I am trying to add a background to my home page, however, it does not seem to be working. Any thoughts? I know how to add it per se, but unsure of how to structure it. I had received some advice to use a Stack, but I am unfamiliar with this method and the resources online are not clear.
Any advice on how to structure this would be appreciated.
Here is the background image code:
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/startbackground.jpg"),
fit: BoxFit.cover),
),
and here is the page code itself.
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.orangeAccent,
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: UnconstrainedBox(
child: Padding(
padding: const EdgeInsets.only(left: 50, bottom: 50),
child: Container(
height: 400,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
child: Text(
"Text",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.teal,
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(15),
child: FlatButton(
minWidth: 200,
onPressed: () {},
child: Text(
"Get Started",
style:
TextStyle(color: Color(0xff7638c9), fontSize: 15),
),
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purple),
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
],
),
),
),
),
),
);
}
}
It's confusing, but we don't actually need a DecoratedBox, rather a BoxDecoration (inside your container, for the decoration: argument).
:P
Here's an example:
class BackgroundImagePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
color: Colors.orangeAccent, // this has been moved up into BoxDeco
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://i.pravatar.cc/300'
)
)
),
height: double.infinity,
width: double.infinity,
... <snip> ...
If the Scaffold is a child of the background image code, than I guess the Scaffold background color is hiding the image.
Set transparent background color for the Scaffold:
Scaffold(
backgroundColor: Color.transparent,
...
This ended up working. See below.
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Stack(children: <Widget>[
Image.asset(
"assets/startbackground.jpg",
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Scaffold(
body: Container(
color: Colors.transparent,
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: UnconstrainedBox(
child: Padding(
padding: const EdgeInsets.only(left: 50, bottom: 50),
child: Container(
height: 400,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
child: Text(
"Text",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
color: Colors.transparent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60,fontWeight: FontWeight.w700),
),
color: Colors.transparent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text(
"Some Text",
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.w700),
),
color: Colors.transparent,
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(15),
child: FlatButton(
minWidth: 200,
onPressed: () {},
child: Text(
"Get Started",
style: TextStyle(
color: Color(0xff7638c9), fontSize: 15),
),
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purple),
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
],
),
),
),
),
),
)
]);
}
}

Styling color with opacity does not work when using the Material () or Scaffold () widget

Defines a background image that will be applied to all screens in the layout, according to the code below.
class _LoginWidgetState extends State<LoginWidget> {
#override
Widget build(BuildContext context) {
return Container(
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.asset(
"assets/img/NewYorkCity.jpeg",
fit: BoxFit.cover,
),
PageView(
children: <Widget>[
SignUpPageWidget(),
LoginPageWidget(),
SignInPageWidget(),
],
)
],
),
);
}
}
And the layout with the Material and Scaffold widgets is not applied stylization color: Colors.white.withOpacity(0.8) and, therefore, the background image is not displayed. The screen is white, as opacity has not been applied to the background.
class _SignUpPageWidgetState extends State<SignUpPageWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.white.withOpacity(0.9),
padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.local_taxi,
size: 50,
color: Theme.of(context).accentColor,
),
Container(
width: double.infinity,
child: Text(
"Already have an account?",
textAlign: TextAlign.center,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 16,
fontWeight: FontWeight.bold,
color: Theme.of(context).accentColor,
),
),
),
CircleButton(
label: "Sign Up",
)
],
),
),
);
}
}
Removing the Scaffold or Material widget, the color: Colors.white.withOpacity (0.8) stylization is applied.
class _SignUpPageWidgetState extends State<SignUpPageWidget> {
#override
Widget build(BuildContext context) {
return Container(
color: Colors.white.withOpacity(0.9),
padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.local_taxi,
size: 50,
color: Theme.of(context).accentColor,
),
Container(
width: double.infinity,
child: Text(
"Already have an account?",
textAlign: TextAlign.center,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 16,
fontWeight: FontWeight.bold,
color: Theme.of(context).accentColor,
),
),
),
CircleButton(
label: "Sign Up",
)
],
),
);
}
}
Would you know how to use the Scaffold and Material widgets by applying this stylization?
Add backgroundColor: Colors.transparent to your Scaffold widget
For Material add type:MaterialType.transparency

Flutter: How to position a logo image based on coordinates?

I don't want to center the image and text, but I want to set a specific coordinate for it. I can't seem to get the alignment command to work.
Currently my logo image and text is posited as following:
I want the logo image and text to be towards the center but a little bit upwards on the y axis, not entirely centered vertically.
This is my main.dart code:
import 'package:flutter/material.dart';
import 'login_page.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
home: new LoginPage(),
theme: new ThemeData(
primarySwatch: Colors.green
)
);
}
}
This is my login_page.dart code:
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget{
#override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>{
#override
Widget build(BuildContext context){
return new Scaffold(
appBar: AppBar(
title: new Text("SMART ID", textAlign: TextAlign.center, style: TextStyle(fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/arrowPNG.png",
scale: 8.0,
)
)
),
backgroundColor: Colors.transparent,
body: Container(
child: Column(
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
}
}
Thanks in advance!
You can move background image and logo inside a Stack and then use Positioned for placing logo from the vertical position.
class LoginState extends State<Login> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SMARTID", textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/images/appicon.png",
scale: 8.0,
)
)
),
backgroundColor: Colors.transparent,
body: Stack(
children: <Widget>[
Container(
alignment: Alignment(0, -0.5),
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.jpg'),
fit: BoxFit.cover,
)
)
),
Positioned(
width: MediaQuery.of(context).size.width,
top: MediaQuery.of(context).size.width * 0.30,//TRY TO CHANGE THIS **0.30** value to achieve your goal
child: Container(
margin: EdgeInsets.all(16.0),
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/appicon.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.white,fontFamily: 'Open Sans',
fontWeight: FontWeight.bold))
]
),
))
],
)
);
}
}
Output
If I understand, I'll try to help you:
First of all, you can Align your Itens in the Center of the Column:
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
After this, you can using Padding or Margin in your container to push up the logo. You can try what distance is better for you. And here's your code:
Container(
padding: EdgeInsets.only(bottom: 25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
I hope it works.