How can I change the background color of a flutter nav drawer?
There doesn't seem to be a color or background-color property.
When you build your ListView in the child property of your Drawer, you can wrap your different sections of the Drawer inside a Container and use the color property of the Container.
drawer: new Drawer(
child: new ListView(
children: <Widget>[
new Container(child: new DrawerHeader(child: new CircleAvatar()),color: Colors.tealAccent,),
new Container (
color: Colors.blueAccent,
child: new Column(
children: new List.generate(4, (int index){
return new ListTile(
leading: new Icon(Icons.info),
);
}),
),
)
],
),
),
A better alternative if you already have a consistent coloring design in your mind, is to define your ThemeData under the theme property of the root of your app, the DrawerHeader and the body will follow your canvasColor, so you need to override the value of one of them to change the color:
return new MaterialApp(
....
theme: new ThemeData(
canvasColor: Colors.redAccent,
....),
)
Best way to wrap Drawer with Theme,
For example:
#override
Widget build(BuildContext context) {
return Scaffold(
//other scaffold items
drawer: Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.blue, //This will change the drawer background to blue.
//other styles
),
child: Drawer(
child: Column(
children: <Widget>[
//drawer stuffs
],
),
),
);
}
The easiest way would probably be to just wrap the ListView inside a Container and specify its color like following:
drawer: Drawer(
child: Container(color: Colors.red,
child: new ListView(
...
)
)
)
For changing Drawer Header color use blow code
UserAccountsDrawerHeader(
accountName: Text("Ashish Rawat"),
accountEmail: Text("ashishrawat2911#gmail.com"),
decoration: BoxDecoration(
color: const Color(0xFF00897b),
),
currentAccountPicture: CircleAvatar(
backgroundColor: Theme.of(ctxt).platform == TargetPlatform.iOS
? const Color(0xFF00897b)
: Colors.white,
child: Text(
"A",
style: TextStyle(fontSize: 40.0),
),
),
),
You can just use this code;
drawer: Drawer(
child: Container(
//child: Your widget,
color: Colors.red,
width: double.infinity,
height: double.infinity,
),
)
PLAIN BACKGROUND
Just set your desired theme color using primarySwatch: Colors.brown property in ThemeData
class MyApp extends StatelessWidget {
final appTitle = 'Drawer Demo';
#override
Widget build(BuildContext context) {
return MaterialApp(
title: appTitle,
theme: new ThemeData(
primarySwatch: Colors.brown, // Your app THEME-COLOR
),
home: MyHomePage(title: appTitle),
);
}
}
GRADIENT BACKGROUND
Add the gradient property to AppBar.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("profyl.org",
style: TextStyle(color: Colors.white),
textDirection: TextDirection.ltr),
flexibleSpace: Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [
const Color(0xFF3366FF),
const Color(0xFF00CCFF),
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
),
),
body: HomeListPage(),
drawer: DrawerPage());
}
Try This.
#override
Widget build(BuildContext context) {
return Drawer(
child: Container(
color: Colors.black,
child: ListView(
padding: const EdgeInsets.all(0),
children: [
],
),
),
);
}
}
This will help
drawer: Drawer(
child: Container(
color: Colors.blueAccent,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(
color: Color(0xFF56ccf2),
),
accountName: Text("User Name Goes"),
accountEmail: Text("emailaddress#gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundColor:
Theme.of(context).platform == TargetPlatform.iOS
? Color(0xFF56ccf2)
: Colors.white,
child: Text("TK",
style: TextStyle(fontSize: 50,
color: Colors.lightGreenAccent,),),
),
),
ListTile(
title: Text('Home',
style: TextStyle(
color: Colors.white,
fontSize: 18,
)),
contentPadding: EdgeInsets.fromLTRB(20, 5, 0, 5),
trailing: Icon(Icons.arrow_right,
color: Colors.white,),
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => HomeScreen()));
},
),
],
),
),
),
The simplest way:
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(color:Theme.of(context).bottomAppBarColor),
)],
),
)
You can wrap whatever you have in your drawer with a container wrapped with expanded widget. Thus you can change the color of the container there. Something like this will work.
Drawer(
child: Expanded(
child: Container(
color: Colors.red,
child: Text('Tabs'),
),
),
)
Related
I tried a column with an aligned icon but it didn't display correctly
If anyone has any idea to help. It would be greatly appreciated. Thank you
This is my code that i tried
List<Widget> temp = [];
listAirline.map((airline) {
listAirlineName.map((item) {
if (airline.name == item) {
temp.add(
Column(
children: <Widget>[
Container(
height: 20,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.elliptical(100.0, 60.0)),
),
child: Image.asset(
"images/Airlines/" + airline.id + ".jpg",
fit: BoxFit.fitWidth,
),
),
Align(
alignment: Alignment.bottomRight,
child: Icon(
Icons.remove_circle,
color: Colors.white,
),
)
],
),
);
}
}).toList();
}).toList();
return temp;
}```
You need to use the Stack widget for it, i have done similar task with the use of the Stack widget,please check thee below solution
class HomeScreen extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return _HomeScreen();
}
}
class _HomeScreen extends State<HomeScreen> {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Container(
height: 100.0,
child: Align(
alignment: Alignment.topCenter,
child: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 20.0),
height: MediaQuery.of(context).size.width*0.15,
width: MediaQuery.of(context).size.width*0.4,
child: Container(
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.all(Radius.elliptical(20.0, 20.0)),
),
),
)
,
Positioned(
right: 5.0,
bottom: 0.0,
child:
Icon(
Icons.remove_circle,
color: Colors.red,
),
)
],
),
)));
}
}
And output of the above code is as follow
I have written this code for a login page and a signup page for a new messenger game.
https://github.com/wileecoyote2point0/math_game
In the emulator I get the error message: Bottom overflowed by Infinity pixels
Can anyone guide me in the right direction?
I tried to implement scrolling view and I tried MainAxisSize.Min
but can't seem to get it to work.
You have used all the rigid Container, Rows and Columns. Instead of Using fixed sized Containers, Use the flexible size container so that they fit the required size.
Here You simple have to put the Expanded Widget Outside the Container widget.
Link of the Working app is Working App Image
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'signup.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(primarySwatch: Colors.purple),
home: new LoginPage(),
routes: <String, WidgetBuilder>{
'/signup': (BuildContext context) => new SignupPage()
});
}
}
class LoginPage extends StatefulWidget {
#override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>
with SingleTickerProviderStateMixin {
Animation<double> _iconAnimation;
AnimationController _iconAnimationController;
#override
void initState() {
super.initState();
_iconAnimationController = AnimationController(
vsync: this,
duration: new Duration(milliseconds: 500),
);
_iconAnimation = new CurvedAnimation(
parent: _iconAnimationController, curve: Curves.easeOut);
_iconAnimation.addListener(() => this.setState(() {}));
_iconAnimationController.forward();
}
#override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.tealAccent,
body: new Stack(
fit: StackFit.expand,
children: <Widget>\[
new Image(
image: new AssetImage("assets/nevroner3.jpg"),
fit: BoxFit.cover,
color: Colors.black87,
colorBlendMode: BlendMode.darken,
),
new Theme(
data: new ThemeData(
brightness: Brightness.dark,
inputDecorationTheme: new InputDecorationTheme(
labelStyle:
new TextStyle(color: Colors.tealAccent, fontSize: 20.0),
),
),
isMaterialAppTheme: true,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>\[
new Image(
image: new AssetImage("assets/math_logo3.png"),
),
Expanded(
child: new Container(
padding: EdgeInsets.all(20.0),
child: new Form(
autovalidate: true,
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>\[
new TextFormField(
decoration: new InputDecoration(
labelText: "Enter Email",
fillColor: Colors.white,
),
keyboardType: TextInputType.emailAddress,
),
new TextFormField(
decoration: new InputDecoration(
labelText: "Enter Password",
fillColor: Colors.white,
),
obscureText: true,
keyboardType: TextInputType.text,
),
new Padding(
padding: const EdgeInsets.only(top: 20.0),
),
new MaterialButton(
color: Colors.teal,
textColor: Colors.white,
child: new Text("Login"),
onPressed: () => {}),
SizedBox(height: 50.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>\[
Text(
"New to Math Messenger ?",
style: TextStyle(
color: Colors.grey,
decoration: TextDecoration.underline),
)
\],
),
SizedBox(height: 20.0),
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/signup');
},
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>\[
Text(
"Register",
style: TextStyle(
color: Colors.tealAccent,
decoration: TextDecoration.underline,
),
),
\],
),
\],
),
),
),
)
\],
),
),
\],
),
);
}
}][1]
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Container(
color: Colors.orange,
child: TextField(
decoration: InputDecoration(
suffix: IconButton(
icon: Icon(Icons.check_circle),
onPressed: () {
print('222');
}),
),
),
),
],
),
),
),
);
}
}
How can I force the check_circle icon to automatically resize to match the height of the actual TextField, i.e., wrt its cursor height?
Use suffixIcon instead.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Container(
color: Colors.orange,
child: TextField(
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.check_circle),
onPressed: () {
print('222');
}),
),
),
),
],
),
),
),
);
}
}
Very good question...
The basics, is to reset all the paddings in the TextField, and not using a IconButton (as all Material components have predefined and internals paddings that you can't modify).
Seems like suffix gets baseline aligned with the text, preventing the material ink interaction, while suffixIcons get properly centered in the text area, BUT propagates the Ink to the TextField.
So, so far I couldn't find a way of doing it properly, maybe there's a widget/logic that I'm missing.
Check screenshot at the bottom that shows why the suffix will not be able to align with the text, as it sits within the baseline itself, and the caret generates a bigger height.....
in the first 2 textfields, the GREY boxes are suffix, and yellow, suffixIcon (which centers properly).
Solution 1: (in screenshotm is red background with 2 checkboxes)
If you can (design-wise), make a row, and put the TextField and the icon:
var inputBorderDecoration = OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide: BorderSide(width: 1, color: Colors.black));
double textHeight = 40;
// define a width if you want, or let the constrains of the parent define it.
double inputWidth = double.infinity;
return Center(
child: Container(
width: inputWidth,
height: textHeight,
color: Colors.green.withOpacity(.2),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: TextField(
controller: TextEditingController(text: 'hello world'),
style: TextStyle(fontSize: textHeight),
decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
enabledBorder: inputBorderDecoration,
focusedBorder: inputBorderDecoration,
filled: true,
fillColor: Colors.red.withOpacity(.5),
),
),
),
FittedBox(
child: InkWell(
onTap: () => print("touch button"),
child: Icon(Icons.check_circle),
),
),
],
)),
);
Solution 2: (in screenshot, last textfield, green box with white icon)
Wrap the icon decoration, is the better UI approach, but the TextField will .still receive touch events.
var inputBorderDecoration = OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide: BorderSide(width: 1, color: Colors.black));
double fontSize = 24;
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Container(
color: Colors.green.shade50,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 300,
height: fontSize,
color: Colors.orange,
child: TextField(
style: TextStyle(fontSize: fontSize, color: Colors.white),
decoration: InputDecoration(
fillColor: Colors.purple.withOpacity(.5),
filled: true,
border: inputBorderDecoration,
focusedBorder: inputBorderDecoration,
enabledBorder: inputBorderDecoration,
contentPadding: EdgeInsets.zero,
suffixIcon: GestureDetector(
onTap: () => print('on tap'),
child: Container(
color: Colors.green,
child: FittedBox(
alignment: Alignment.center,
fit: BoxFit.fitHeight,
child: IconTheme(
data: IconThemeData(),
child: Icon(
Icons.check_circle,
color: Colors.white,
),
),
),
),
),
),
),
),
],
),
),
),
);
Solution 3:
Build the decorations yourself using EditableText
Used Stack
Stack(
children: [
TextField(),
Positioned.fill(
right: 10,
child: Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {
searchController.clear();
},
child: Icon(Icons.clear))))
],
),
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.
I want to create a tranparent UI in flutter.
Can you help me with the code?
Here is the link to the stuff I need.
https://dribbble.com/shots/3958928-Wikipedia-App/attachments/904403
https://dribbble.com/shots/1081917-WhereTO-App
https://dribbble.com/shots/1539644-App-Mockup
https://dribbble.com/shots/1254375-Events-More/attachments/171069
This example my help to resolve your problem
Code Snippet
Widget build(BuildContext context) {
List list = ['Introduction','Early life', 'Non-Film work', '2012-present', 'Controversy'];
return new Container(
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Image.asset('assets/bg_img.jpg', fit: BoxFit.fitHeight,),
new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
elevation: 0.0,
backgroundColor: const Color(0xFFB4C56C).withOpacity(0.5),
),
backgroundColor: Colors.transparent,
body: new Center(
child: new Center(
child: new BackdropFilter(
filter: new ui.ImageFilter.blur(
sigmaX: 6.0,
sigmaY: 6.0,
),
child: new Container(
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: const Color(0xFFB4C56C).withOpacity(0.01),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: new Container(child: ListView.builder(itemBuilder: (contex, index){
return index == 0?new Container(
height: 50.0,
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 12.0),
decoration: BoxDecoration(
color: const Color(0xFFB4C56C).withOpacity(0.7),
borderRadius: BorderRadius.all(Radius.circular(25.0)),
boxShadow: [new BoxShadow(color: Colors.black12,offset: new Offset(2.0, 2.0), blurRadius: 2.0 )]
),child: new Row(children: <Widget>[
new Icon(Icons.info, color: Colors.white,),
new SizedBox(width: 8.0),
new Text(list[index], style: TextStyle(color: Colors.white70, fontSize: 18.0))
],),
):new ListTile(title: new Text(list[index], style: TextStyle(color: Colors.white),), leading: new Text('${index}',
style: TextStyle(color: const Color(0xFFB4C56C), fontSize: 18.0)),);
}, itemCount: list.length,),),
),
),
),
),
)
],),
);
}
Complete source code can be dowloaded from here blue_effect
You can override PageRoute like this
import 'package:flutter/cupertino.dart';
class TransparentRoute extends PageRoute<void> {
TransparentRoute({
#required this.builder,
RouteSettings settings,
}) : assert(builder != null),
super(settings: settings, fullscreenDialog: false);
final WidgetBuilder builder;
#override
bool get opaque => false;
#override
Color get barrierColor => null;
#override
String get barrierLabel => null;
#override
bool get maintainState => true;
#override
Duration get transitionDuration => Duration(milliseconds: 350);
#override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
final result = builder(context);
return FadeTransition(
opacity: Tween<double>(begin: 0, end: 1).animate(animation),
child: Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: result,
),
);
}
}
/// And you can push like this
Navigator.of(context).push(
TransparentRoute(
builder: (BuildContext
context) =>
TransParentView()));
///New container to push
class TransParentView extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black.withOpacity(0.6),
body: Padding(
padding: const EdgeInsets.all(27.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5))),
height: 700,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: 60,
),
Container(
width: 160,
height: 100,
),
Container(
height: 290,
width: 250,
),
Container(
height: 150,
),
],
),
),
),
),
);
}
}
Hope this will help.
Just surround the widget or widget tree you want to make transparent with an Opacity widget and specify the opacity value from 0.0 to 1.0
For example:
0.0 means completely invisible,
0.5 means half way transparent,
1.0 means fully visible.