I have this Code:
new Container(
padding: new EdgeInsets.only(
top: 20.0,
),
alignment: FractionalOffset.centerRight,
child: new GestureDetector(
child: new Text('Forgot password?', style: new TextStyle(color: Color(0xFF2E3233))),
),
),
new Container(
width: 300.0,
height: 45.0,
alignment: FractionalOffset.center,
decoration: new BoxDecoration(
color: const Color(0xFF2E3233),
borderRadius: new BorderRadius.all(const Radius.circular(30.0)),
),
child: new Text("Sign in",style: new TextStyle(color: Colors.white,fontWeight: FontWeight.bold,letterSpacing: 0.3,),),
),
new Container(
padding: new EdgeInsets.only(
top: 20.0,
),
alignment: FractionalOffset.center,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new GestureDetector(
child: new Text('Don\'t have an account?', style: new TextStyle(color: Color(0xFF2E3233))),
),
new GestureDetector(
child: new Text('Register.', style: new TextStyle(color: Color(0xFF84A2AF), fontWeight: FontWeight.bold),),
onTap: moveToRegister,
),
],
),
),
Thats the result:
https://www.dropbox.com/s/bqu2tv6rej0ejlt/Screenshot_20181104-171155.png?dl=0
But I want to achieve this:
https://www.dropbox.com/s/754hempszq8xw5k/Screenshot_20181104-171202.png?dl=0
EDIT:
build method:
#override
Widget build(BuildContext context) {
return new Stack(
children: <Widget>[
// The containers in the background
new Column(
children: <Widget>[
new Container(
height: MediaQuery.of(context).size.height * .44,
color: const Color(0xFF84A2AF),
padding: new EdgeInsets.only(
top: 50.0,
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
new Image.asset('assets/app_logo_transparent_bg.png',
height: 100.0,
width: 100.0,
),
],
),
),
new Container(
height: MediaQuery.of(context).size.height * .56,
color: Colors.white,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Align(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: buildSubmitButtons(),
),
),
],
)
/*child: new Align(
alignment: Alignment.bottomCenter,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: buildSubmitButtons(),
),
),*/
),
],
),
// The card widget with top padding,
// incase if you wanted bottom padding to work,
// set the `alignment` of container to Alignment.bottomCenter
new Container(
alignment: Alignment.topCenter,
padding: new EdgeInsets.only(
top: MediaQuery.of(context).size.height * .33,
right: 15.0,
left: 15.0),
child: new Container(
height: 130.0,
width: MediaQuery.of(context).size.width,
child: new Card(
color: Colors.white,
elevation: 2.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: buildInputs(),
),
),
),
)
],
);
}
I tried so much but nothing seems to help? How I can align the Layout to the bottom...
Just a few changes on your container (.56) , remove the Align widget, stretch your Column and add an Expanded item inside your Column to fill the space available.
new Container(
height: MediaQuery.of(context).size.height * .56,
color: Colors.white,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Container(),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.end,
children: buildSubmitButtons(),
),
),
],
)
/*child: new Align(
alignment: Alignment.bottomCenter,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: buildSubmitButtons(),
),
),*/
),
Probably you will need to move your 'Forgot password' above the Expanded widget inside your Column.
Related
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: size.height * 0.4,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/user2.jpg"),
fit: BoxFit.cover,
),
),
child: Column(
children: <Widget>[
SizedBox(
height: size.height * 0.125,
),
Container(
height: 100,
width: 100,
//Circle Avatar
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset(
'assets/images/user2.jpg',
fit: BoxFit.cover,
),
),
),
],
),
)
],
),
),
Try this code with BackdropFilter:
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: size.height * 0.4,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/user2.jpg"),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.0),
),
child: Column(
children: <Widget>[
SizedBox(
height: size.height * 0.125,
),
Container(
height: 100,
width: 100,
//Circle Avatar
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset(
'assets/images/user2.jpg',
fit: BoxFit.cover,
),
),
),
],
),
),
),
),
],
),
);
This is my source code:
Scaffold(
body: Center(
child: Container(
color: Colors.green,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
fit: FlexFit.loose, child: Image.asset('images/demo.png')),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
],
),
),
),
);
This is the result:
I want it to be like this:
without using fixed sizes because the image dimensions may vary.
I already tried to use flexible on the row children. The problem with that solution is that the green container is being expanded like this:
which I don't want to happen.
EDIT, Did a little more searching and found what you seem to be looking for:
The IntrinsicWidth widget makes sure children have uniform width, which will be the width of the widest element (without the overlapping issue like in the Stack widget based solution). So this code accomplishes what you're trying to do:
Scaffold(
body: Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Image.asset('images/demo.png'),
),
Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
],
),
),
),
);
Screenshot:
OLD ANSWER:
If you don't mind overlapping a little bit of the bottom of the image with the buttons, the stack class sizes itself to its non positioned children, so this would work for you:
Scaffold(
body: Center(
child: Stack(
fit: StackFit.loose,
children: [
Image.asset('images/demo.png'),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
),
],
),
),
);
Screenshot:
Maybe this will help.
You can use Spacer(); between the two text Cancel & Okay. Spacer() will put second text to end of row.
Row(
children[
Container(child: Text('Cancel', style...)),
Spacer(),
Container(Text('Okay', style...)),
]
);
maybe you can get the width of the image and pass it to the container that wraps the column:
import 'dart:io';
File image = new File('image.png'); // Or any other way to get a File instance.
var decodedImage = await decodeImageFromList(image.readAsBytesSync());
final width = decodedImage.width;
I am using the https://pub.dev/packages/flutter_sliding_up_panel dependency and I want to round the edges of the panel below.
This is the code I am using
SlidingUpPanelWidget(
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(35.0),
topRight: Radius.circular(35.0),
),
child: Container(
color: Colors.red,
alignment: Alignment.center,
child: Row(
children: <Widget>[
Icon(
Icons.menu,
size: 30,
),
Padding(
padding: EdgeInsets.only(
left: 8.0,
),
),
Text(
'click or drag',
)
],
mainAxisAlignment: MainAxisAlignment.center,
),
height: 50.0,
),
),
Divider(
height: 0.5,
color: Colors.grey,
),
Flexible(
child: Container(
child: ListView.separated(
controller: scrollController,
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
return ListTile(
title: Text('list item $index'),
);
},
separatorBuilder: (context, index) {
return Divider(
height: 0.5,
);
},
shrinkWrap: true,
itemCount: 20,
),
color: Colors.white,
),
),
],
mainAxisSize: MainAxisSize.min,
),
controlHeight: 50.0,
anchor: 0.4,
panelController: panelController,
),
and this is what the collapsed panel currently looks like:
I want the entire panel to be as rounded as the red container.
You can't do it. The library has a hardcoded Material widget around the widget you give it.
The only thing you can do is to copy the whole library and modify it. It is a small library only has one file you need to copy.
At line 192 in the library you have this code:
child: Material(
key: _childKey,
color: Theme.of(context).backgroundColor,
elevation: widget.elevation,
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: widget.child,
),
),
Modify it like this:
child: Material(
key: _childKey,
color: Colors.transparent,
shadowColor: Colors.transparent,
elevation: widget.elevation,
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: widget.child,
),
),
I want to display this screen like FullScreen Background Image->4 Card/Container/Listview.count with child background image->Button with text. How I can do that? Background Image>Widget(Card, Container etc)>background image covered with child widget>text. I am using it as a dashboard of my app. I read a lot of questions and answers about the full-screen background but child background I couldn't find.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:onlycentertainment/constants/constants.dart';
class Dashboard extends StatefulWidget {
#override
_DashboardState createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
final _scaffold = GlobalKey<ScaffoldState>();
final _formKey = GlobalKey<FormState>();
String username;
submit() {
final form = _formKey.currentState;
if (form.validate()) {
form.save();
SnackBar snackBar = SnackBar(content: Text('Welcome $username'));
_scaffold.currentState.showSnackBar(snackBar);
Timer(Duration(seconds: 2), () {
Navigator.pop(context, username);
});
//Page pop to next including saved data
}
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Stack(
alignment: Alignment.center,
children: <Widget>[
BackgroundWidget(size: size),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10,
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'HELLO, USER',
style: TextStyle(
fontSize: 25,
color: Colors.white,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(top: 30, bottom: 30),
child: Text(
'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.',
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
maxLines: 5,
),
),
],
),
),
Container(
height: MediaQuery.of(context).size.height * .6,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: Card(child: Text('1')),
),
Container(
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: Card(child: Text('1')),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/asset5.png"),
fit: BoxFit.fitHeight
),
),
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: GestureDetector(
child: Text('This is my text',style: TextStyle(fontSize: 20, color: Colors.white),),),
),
Container(
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: Card(child: Text('1')),
),
],
)
],
)
],
),
),
],
),
],
),
),
),
);
}
}
Now it works!
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:onlycentertainment/constants/constants.dart';
class Dashboard extends StatefulWidget {
#override
_DashboardState createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
final _scaffold = GlobalKey<ScaffoldState>();
final _formKey = GlobalKey<FormState>();
String username;
submit() {
final form = _formKey.currentState;
if (form.validate()) {
form.save();
SnackBar snackBar = SnackBar(content: Text('Welcome $username'));
_scaffold.currentState.showSnackBar(snackBar);
Timer(Duration(seconds: 2), () {
Navigator.pop(context, username);
});
//Page pop to next including saved data
}
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Stack(
alignment: Alignment.center,
children: <Widget>[
BackgroundWidget(size: size),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10,
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'HELLO, USER',
style: TextStyle(
fontSize: 25,
color: Colors.white,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(top: 30, bottom: 30),
child: Text(
'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.',
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
maxLines: 5,
),
),
],
),
),
Container(
height: MediaQuery.of(context).size.height * .6,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/asset5.png"),
fit: BoxFit.fitHeight
),
),
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: GestureDetector(
child: Text('This is my text',style: TextStyle(fontSize: 20, color: Colors.white),),),
),
SizedBox(width:10),
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/asset5.png"),
fit: BoxFit.fitHeight
),
),
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: GestureDetector(
child: Text('This is my text',style: TextStyle(fontSize: 20, color: Colors.white),),),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/asset5.png"),
fit: BoxFit.fitHeight
),
),
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: GestureDetector(
child: Text('This is my text',style: TextStyle(fontSize: 20, color: Colors.white),),),
),
SizedBox(width:10),
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/asset5.png"),
fit: BoxFit.fitHeight
),
),
height:
MediaQuery.of(context).size.height * .3,
width: MediaQuery.of(context).size.width * .4,
child: GestureDetector(
child: Text('This is my text',style: TextStyle(fontSize: 20, color: Colors.white),),),
),
],
)
],
)
],
),
),
],
),
],
),
),
),
);
}
}
I'm working on a Flutter application and I can't figure out why my icon-buttons are not centered in the middle of the page.
I wrapped my code in a Center()
This is my page :
https://imgur.com/a/YlCW3Xu
This is my code:
import "package:flutter/material.dart";
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class LogInScreen extends StatefulWidget {
#override
_LogInScreenState createState() => new _LogInScreenState();
}
class _LogInScreenState extends State<LogInScreen> {
String _email, _password;
#override
Widget build(BuildContext context) {
return new Scaffold(
body: Center(
child: ListView(
children: <Widget>[
Column(children: <Widget>[
new Container(
padding: (EdgeInsets.only(top: 50)),
child: Text(
"Sign In",
style: TextStyle(
fontSize: 40,
),
),
),
new Container(
padding: (EdgeInsets.only(top: 50, left: 35, right: 35)),
child: Column(children: <Widget>[
new Form(
child: new Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 20),
child: new RaisedButton(
onPressed: () {},
color: Colors.blue,
textColor: Colors.white,
child: const Text('Login'),
),
),
])),
])),
new Container(
padding: EdgeInsets.only(top: 40),
child: Column(
children: <Widget>[
new Text("Or login with"),
],
),
),
]),
new Center(
child: new Row(
children: <Widget>[
new IconButton(
icon: Icon(FontAwesomeIcons.facebookF),
color: Colors.blue,
),
new IconButton(
icon: Icon(FontAwesomeIcons.google),
color: Colors.blue,
),
],
)),
],
)),
);
}
}
I removed the texts field so the code would fit.
I hope you can help me,
Thank you for your help !
Set the padding for IconButton to 0, like so:
IconButton(
padding: EdgeInsets.zero,
...
)
None of the listed solution will work. The Only solution for me is to put IconButton inside SizedBox.
SizedBox(
width: double.infinity,
child: IconButton(
icon: FaIcon(FontAwesomeIcons.moneyBillWave),
iconSize: 80,
onPressed: () {},
),
),
A few changes :
Add shrinkWrap true to your ListView
ListView(
shrinkWrap: true,
...
Add mainAxisAlignment MainAxisAlignment.center to your Row
new Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new IconButton(
...
Basically Center() widget only center the row itself not the widgets within the row.
To align children in your row use mainAxisAlignment: MainAxisAlignment.centerfor horizontal alignment and crossAxisAlignment: CrossAxisAlignment.center for Vertical alignment see more here
so for your code it would be:
` new Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center
children: <Widget>[
new IconButton(
icon: Icon(FontAwesomeIcons.facebookF),
color: Colors.blue,
),
new IconButton(
icon: Icon(FontAwesomeIcons.google),
color: Colors.blue,
),
],
)),`
You don't need Center the icon because the problem was the Icon it self. Maybe the icon design contained padding or margin. My problem is on back button:
Container(
color: Colors.lightGreen,
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 15,
),
),
When i change to Icons.arrow_back_ios_new, it back to normal:
Container(
color: Colors.lightGreen,
child: Icon(
Icons.arrow_back_ios_new,
color: Colors.black,
size: 15,
),
),
You need to find an icon that contained no padding/margin.