How to left align text title in app bar (ios) in flutter? - ios

How to left align text title in app bar?
In android: they're still left-aligned, but ios: they're center-aligned title.
How to fix that?
AppBar(
titleSpacing: 0,
centerTitle: false,
automaticallyImplyLeading: false,
leadingWidth: 0,
title: Image.asset(Images.appLogo, height: 28, width: 28)
);

You can set the platform parameter in the ThemeData of the app to TargetPlatform.android. Then the app will behave as if it were running on an android device!
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
platform: TargetPlatform.android,
),
home: Scaffold(
appbar: AppBar(
automaticallyImplyLeading: false,
leadingWidth: 0,
title: Image.asset(Images.appLogo, height: 28, width: 28)
);
body: Container(),
),
),
);
}

In iOS app title have always a center aligned behaviour. If you need align title in left side so you can follow below the code....
appBar: AppBar(
title: const Text('Restaurant Menu'),
centerTitle: false,
),

You can Wrap your Text Widget with Row:
appBar: AppBar(
title: Row(
children: const [
Text(
"Title",
),
],
),
),
OR simply use centerTitle: false;
appBar: AppBar(
title: const Text("Title"),
centerTitle: false,
),

Related

How to wrap Text on AppBar

I added sub-Appbar on my application. How to view all text on the app bar without reducing font size?
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: submitRequestAppBar(context),
body: Scaffold(
appBar:
PreferredSize(
preferredSize: Size.fromHeight(40.0),
child:
AppBar(
backgroundColor: Colors.grey[350],
leading: Container(),
title: Text(
widget.title,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 15.0),
),
),
),
You can create an scroll-animation to show the text that doesn't fit the screen. You can use this widget, the marquee. It's open-source so if you want to contribute you can just fork it and create a pull-request, from here.
It it's only wrapping you are after and don't care about the design. Then you should look into the solution on SO.

Align Scrollable Tabs On Left

When i set my tabs to scrollable, it will set all my tabs to the center. But i want to find a way that i can align all the tabs to the left. Is there a way for me align the tabs on the left instead of center? Here is my code. Thank you.
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: colorPrimary,
accentColor: colorAccent,
),
home: DefaultTabController(
length: 3,
child: Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(
child: Text(sign_in),
),
Tab(
child: Text(sign_up),
),
Tab(
child: Text(reset_password),
),
],
indicatorColor: colorWhite,
isScrollable: true,
),
),
body: TabBarView(
children: [
SignIn(),
SignUp(),
ResetPassword(),
],
),
),
),
);
}
}
For those who are interested, this is the answer that works form me

changing status bar color works for some pages only

am trying to change the status bar color of my app to dark
i have followed this How to change status bar color in Flutter?
and did this:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
but for some reason it works only for some pages and the others will still be white!!
for example this page:
#override
Widget build(BuildContext context) {
final theme = Theme.of(context).copyWith(unselectedWidgetColor: Colors.red);
Animation opacityAnimation =
Tween(begin: 0.0, end: 1.0).animate(animationController);
return new Directionality(
textDirection: TextDirection.rtl,
child: new Theme(
data: theme,
child: new Scaffold(
key: scaffoldKey,
drawer: globals.drawer(context),
appBar: new AppBar(
leading: IconButton(
icon: Icon(
CustomFont.burger,
color: Color(0xff474747),
),
onPressed: () {
scaffoldKey.currentState.openDrawer();
},
),
centerTitle: true,
elevation: 0.0,
bottom: PreferredSize(
child: Container(
color: Color(0xff2CB57D),
height: 0.20,
),
preferredSize: Size.fromHeight(0.20)),
backgroundColor: Colors.white,
title: new Image.asset(
'assets/appbar-icon.png',
width: 55.0,
height: 27.0,
),
actions: <Widget>[
IconButton(
icon: Icon(
CustomFont.home,
color: Color(0xff474747),
),
onPressed: () {
globals.goToHome(context);
},
),
],
),
body: ......
),
);
}
the color of this page is always white no matter if i changed or not!
why is this happening? and how to solve it?

Flutter how to get subtext aligned under title in appbar?

I have the following app bar in flutter and trying to align the subtext "Your desired business name" under the title enter. I have tried different methods but still can't get to align. It should have "enter" at the top and then the subtext aligned center
Here is my current code
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(75.0),
child: AppBar(
centerTitle: true,
title: Text('enter'),
actions: <Widget>[
new Container(),
new Center(
child: Text(
'Your desired business name',
textAlign: TextAlign.center,
style: new TextStyle(
fontSize: 14.0,
color: Colors.white,
),
)),
],
)),
);
}
To align Text under AppBar title you can use bottom property of AppBar which takes PreferredSize widget as a parameter which also helps you to adjust the height of AppBar according to your need.
Here's the code
AppBar(
title: Text('Title 1'),
centerTitle: true,
bottom: PreferredSize(
child: Text("Title 2"),
preferredSize: Size.zero),
)
The menu bar actions widgets get aligned on the right and as far as I know it is not possible to obtain your desidered layout.
Should you consider a column based widget with a title and subtitle:
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
centerTitle: true,
title: Column(children: [
Text(
"Title",
),
GestureDetector(
child: Text('subtitle'),
onTap: () {
print("tapped subtitle");
},
)
]),
...
In this example there is a GestureDetector for give interactivity to subtitle, since it seems it is what you are trying to do.
I am using this code for adding subtitle and show UserIcon
//name,status and userPic are variable's
#override
Widget build(BuildContext context)
{
return new Scaffold(
appBar: new AppBar(
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
Text(
status,
style: TextStyle(color: Colors.white, fontSize: 14.0),
)
],
),
leading: new Padding(
padding: const EdgeInsets.all(5.0),
child: new CircleAvatar(
backgroundImage: new NetworkImage(userPicUrl),
),
),
actions: <Widget>[new Icon(Icons.more_vert)],
),
);
}
Output
You should add Column view.
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Title",
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
Text(
"Sub Title",
style: TextStyle(color: Colors.white, fontSize: 14.0),
),
]
),
In these cases I prefer to use a ListTile:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar:
AppBar(
title:
ListTile(
title:
Text("Enter", style: TextStyle(color:Colors.white)),
subtitle:
Text("Your desired business name", style: TextStyle(color:Colors.white)),
)
),
);
}
If you need the Text widget centered just wrap it within a Center widget.
The answer in https://stackoverflow.com/a/53880971/9185192 works but with null safety landing in Dart it is not allowed to set preferredSize to null.
So the solution is to set preferredSize to zero or any other valid number.
appBar: AppBar(
title: Text('Title 1'),
centerTitle: true,
bottom: PreferredSize(
child: Text("Title 2"),
preferredSize: Size.fromHeight(0),
),
)
appBar: AppBar(
title: Center(
child: Text('Flutter Tutorial'),
),

Flutter how to use ListTile Threeline

Flutter when I used ListTile ThreeLines, I don't know how to use ThreeLine
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('ddd'),
),
body:Container(
child: Column(
children: <Widget>[
ListTile(
isThreeLine: true,
leading: Icon(Icons.event_note),
title: Text('Title 1'),
// subtitle: Text('Title2'),
subtitle: Column(
children: <Widget>[
Text('Titile2'),
Text('Title 3'),
Text('Title 4'),
Text('and so on')
],
),
)
],
),
) ,
),
);
}
}
When i delete isThreeLines, the code is Ok
ListTile
Thanks
As from the docs:
The value of subtitle, which is optional, will occupy the space
allocated for an additional line of text, or two lines if isThreeLine
is true.
It basically means the subtitle of the ListTile is given more space to have text which is more than one line in length:
By default, the ListTile in flutter can display only 2 lines. The Title and the SubTitle. In case there is a third line of text to be displayed, the isThreeLine is set to true and can allow another line to be present. The subtitle will be taking care of giving the 3rd line of text. It is expected that, if the isThreeLine is set to true, the subtitle should be non-null. Anything after "\n" inside subtitle will come in next line
ListTile(
title: Text("First Line",
style: TextStyle(fontWeight: FontWeight.bold)),
subtitle: Text("Second One Text "\nThis is Line Third Text"),
isThreeLine: true,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(Icons.delete,color: Colors.red,),
onTap: () {
},
),
],
),
onTap: (){},
)
By default, the ListTile in flutter can display only 2 lines. The Title and the SubTitle. In case there is a third line of text to be displayed, the isThreeLine is set to true and can allow another line to be present. The subtitle will be taking care of giving the 3rd line of text. It is expected that, if the isThreeLine is set to true, the subtitle should be non-null.

Resources