How to position this text in container in Flutter? - flutter

I'm re-writing my application written in Kotlin to Flutter, but I'm struggling with simple layout.
I'm trying to re-create layout from Gmail, but I don't know how to position some things.
This is an image from the Kotlin app:
This is an image from my Flutter app:
I'm talking about the "odebrane" text. I want it to be exactly like in my Kotlin app. I want the text inside it to be centered and I want it to be on the exact height to the "Voucher" text. Is there anyone who can help me?
Code:
import 'package:flutter/material.dart';
class GeneratedMailCouponScreen extends StatelessWidget {
final String couponImage;
GeneratedMailCouponScreen({Key key, #required this.couponImage}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.arrow_back
)
],
),
Row(
children: [
Icon(
Icons.archive
),
SizedBox(width: 5.0),
Icon(
Icons.delete
),
SizedBox(width: 5.0),
Icon(
Icons.mail
),
SizedBox(width: 5.0),
Icon(
Icons.more_vert
)
],
)
],
),
SizedBox(height: 16.0),
Row(
children: [
Text('Voucher', style: TextStyle(color: Colors.black, fontSize: 20.0)),
SizedBox(width: 16.0,),
Container(
color: Colors.grey[300],
width: 50.0,
height: 8.0,
child: Center(
child: Text('Odebrane', style: TextStyle(color: Colors.black, fontSize: 8.0),),
)
)
],
)
],
),
),
),
);
}
}

After test on device, this is my solution
You only need to change few line of code
// from
Container(
color: Colors.grey[300],
width: 50.0,
height: 8.0,
child: Center(
child: Text('Odebrane', style: TextStyle(color: Colors.black, fontSize: 8.0),),
)
)
// to
Container(
color: Colors.grey[300],
child: Padding(
padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
child: Text('Odebrane', style: TextStyle(color: Colors.black, fontSize: 10.0),),
)
)

Related

How can I center Row widget in container Flutter?

I want to center the Row widget in Container but can't do it.
Desire Design
My desire Design look like this : -
but I'm getting this output
My Output : -
Here is my code : -
Container(
height: Dimensions.height40,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(Dimensions.radius10), color: Colors.white),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions.width45),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
],
),
),
),
SmallText
class SmallText extends StatelessWidget {
final Color? color;
final String text;
final double size;
final TextAlign? align;
const SmallText({
Key? key,
this.color = const Color(0xffCF1357),
this.size = 16,
required this.text, this.align=TextAlign.center,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Text(
text,
textAlign: align,
style: TextStyle(
color: color, fontSize: size, fontFamily: 'ROCK'),
);
}
}
Replace your Row widget
From
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
],
),
To
Row(
children: [
Icon(Icons.chevron_right_outlined, color: Colors.red),
Expanded(
child: Text(
"asdfasdfasdfadsfadsf",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red, fontSize: 12, fontFamily: 'ROCK'),
),
),
],
),
try this way...
Container(
height: Dimensions.height40,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(Dimensions.radius10), color: Colors.white),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions.width45),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
// if text overflowing
// Expanded(child: Text('text', maxLines: 2)),
],
),
),
),
Try below code:
ElevatedButton(
onPressed: () {},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.network(
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTffY2_D5YjjG8Mn3NnOFrXG2Piu72Ff5rbyHiyZXFvkWWtE3pLojAwOXpxAbC7PZa0JpU&usqp=CAU',
height: 40,
), //use your google image here
Text(
'Sign in with Google',
style: TextStyle(
color: Colors.black,
),
),
SizedBox()
],
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white, fixedSize: const Size(250, 50)),
),
Result->

A page I made was fine last night but now only shows me black and red

I don't know what I did wrong.
import 'package:flutter/material.dart';
import 'package:nle_app/models/stall.dart';
import 'package:nle_app/constants/colors.dart';
class StallInfo extends StatelessWidget {
final stall = Stall.generateRestaurant();
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 40),
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
stall.name,
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Row(
children: [
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blueGrey.withOpacity(0.4),
borderRadius: BorderRadius.circular(5),
),
child: Text(
stall.label,
style: const TextStyle(
color: Colors.white,
),
)),
const SizedBox(
width: 10,
),
],
)
],
),
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset(
stall.logoUrl,
width: 80,
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
stall.desc,
style: const TextStyle(fontSize: 16),
),
Row(
children: [
const Icon(
Icons.star_outline,
color: Colors.amber,
),
Text(
'${stall.score}',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 15),
],
)
],
)
],
),
);
}
}
The image I uploaded shows what its suppossed to look like but in case you missed it, it's supposed to look like .
I thought maybe the image overflowed to the right but even when I remove the image it's the same thing.
I've tested it on different devices but it's all the same. It doesn't even throw an exception or anything. Does anyone know how to fix this.
It is missing material, Check if the parent widget contains Scaffold. Also for this one , you can wrap with any material widget like Material, Card,Scaffold....
Widget build(BuildContext context) {
return Material(
child: Container(
```

Flutter UI Place button on the edge of two containers

How to create an UI like above just the part where the Edit Profile button is on the edge of both the containers ? I used stack and positioned but didnt work out for me . Can somebody help me with this . How to approach this .
try this code no perfect but it will give you some idea
Container(
height: double.infinity,
width: double.infinity,
color: Colors.red,
child: Stack(children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.white,
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 8.0,
offset: Offset(0.0, 5.0),
),
],
),
width: double.infinity,
child: Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 15.0),
child: Column(
children: <Widget>[
const SizedBox(
height: 30.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: const <Widget>[
Text(
'Year',
style: TextStyle(
fontSize: 20.0,
color: Colors.black54,
),
),
Text(
'Sophmor',
style: TextStyle(
fontSize: 34.0,
color: Colors.black87,
fontFamily: ''),
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: const <Widget>[
Text(
'Year',
style: TextStyle(
fontSize: 20.0,
color: Colors.black54,
),
),
Text(
'Sophmor',
style: TextStyle(
fontSize: 34.0,
color: Colors.black87,
fontFamily: ''),
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: const <Widget>[
Text(
'Year',
style: TextStyle(
fontSize: 20.0,
color: Colors.black54,
),
),
Text(
'Sophmor',
style: TextStyle(
fontSize: 34.0,
color: Colors.black87,
fontFamily: ''),
),
],
),
],
),
)
],
)),
),
Container(
width: 80,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
borderRadius: BorderRadius.circular(15.0), ),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Center(
child: Container(
child: const Text('Edit Profile'),
),
),
),
),
],
),
),
]),
);
Instead of using Stack you can use Transform.translate to shift the TextButton up by the half of its height:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: const Text('Material App Bar'),
),
body: Column(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.bottomCenter,
color: Color(0xFFF09384),
),
),
Expanded(
flex: 3,
child: Container(
alignment: Alignment.topCenter,
color: Color(0xFF3E8C92),
child: Column(
children: [
Transform.translate(
offset: Offset(0,-35/2), // Here you insert the half of the button height
child: TextButton(
onPressed: () => print("Hello"),
child: Text("Edit Profile"),
style: TextButton.styleFrom(
fixedSize: Size(120, 35), // Here you should fix the size of the button
backgroundColor: Colors.white,
primary: Color(0xFF3E8C92),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)
)
),
),
),
...List<Text>.filled(5, Text("Data"))
]
),
),
),
],
)
),
);
}
}

how to guarantee that the box that contains date and time will be always centered after calling the card in list view

i am a beginner in flutter , i am trying to correct the display of this widget in flutter ,
the problem is that this widget is not responsive where the name of the teams when they are long they can make the screen out of range , and also the time and date zone is not always centered , i am searching how to make the date and the time zone always centered in the screen in all the cases , how to replace the padding ? by container?? what prosperities to change???
my goal is to make the date and the time centered in all the cases and my second goal is to find a solution for the width of screen when the name of teams are long
here my widget class :
import 'package:flutter/material.dart';
class BroadcastSchedule extends StatelessWidget {
String home;
String homeImage;
String away;
String awayImage;
String time;
String date;
BroadcastSchedule(this.home,this.homeImage,this.away,this.awayImage,this.time,this.date);
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
const SizedBox(width:10.0),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home),
const SizedBox(height: 5.0, ),
],
),
Padding(
padding: EdgeInsets.only(top:20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(this.time,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),),
const SizedBox(height: 5.0, ),
Text(this.date,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white
),),
],
),
),
),
Expanded(
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget> [
Text(this.away),
const SizedBox(height: 5.0, ),
],
),
),
Spacer(),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
);
}
}
here the screen capture :
how can we replace padding that contains the date and time of a match by something that will be centered in all the cases
I Think you're looking for this.
final Result Looks like this.
Final Ouput
class BroadcastSchedule extends StatelessWidget {
final String home;
final String homeImage;
final String away;
final String awayImage;
final String time;
final String date;
BroadcastSchedule({
this.home,
this.homeImage,
this.away,
this.awayImage,
this.time,
this.date,
});
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
SizedBox(
width: 10.0,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(this.home),
const SizedBox(
height: 5.0,
),
],
),
),
],
),
),
Expanded(
flex: 1,
child: Padding(
padding: EdgeInsets.only(top: 20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(
this.time,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),
),
const SizedBox(
height: 5.0,
),
Text(
this.date,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white),
),
],
),
),
),
),
Expanded(
flex: 1,
child: Row(
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
this.away,
overflow: TextOverflow.fade,
),
SizedBox(
height: 5.0,
),
],
),
),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
],
),
),
);
}
}
Column(crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home),
const SizedBox(height: 5.0, ),
],
),
Please change it. Don't use the column it's unneccessary.
Instead, You can use a container of fixed-sized (fixed height and width). So, that it can wrap text according to its length.
The problem caused by the length of this.home string. You can wrap that text inside the container of fixed length. so, that your date and time is shown always at the center.
Try this code,
import 'package:flutter/material.dart';
class BroadcastSchedule extends StatelessWidget {
String home;
String homeImage;
String away;
String awayImage;
String time;
String date;
BroadcastSchedule(this.home,this.homeImage,this.away,this.awayImage,this.time,this.date);
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
const SizedBox(width:10.0),
Spacer(),
Container(
width: MediaQuery.of(context).size.width * 0.22,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home,softWrap: true,),
const SizedBox(height: 5.0, ),
],
),
),
Padding(
padding: EdgeInsets.only(top:20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(this.time,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),),
const SizedBox(height: 5.0, ),
Text(this.date,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white
),),
],
),
),
),
Expanded(
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget> [
Text(this.away),
const SizedBox(height: 5.0, ),
],
),
),
Spacer(),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
);
}
}
IF it's not center try to change the length of the container.

Divider in AppBar not appearing

I am struggling to figure out why my divider in my app bar is not appearing. When I increase the height of the divider, I notice my widgets move up. I looked at similar issues and none have worked. My appBar consists of two columns and one row for the user profile information and information on their "Partner". I wanted to use the divider to separate the partner name and username from the win/loss ratio.strong text
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF2430346),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(100.0),
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left:20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildUserInfo(user),
Text(
"#username",
style: new TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white,
)
)
],
),
),
),
Padding(
padding: const EdgeInsets.only(right:70.0),
child: Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"My Partner",
style: new TextStyle(
fontSize: 24,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
Text(
"Dorian",
style: new TextStyle(
color: Colors.white,
),
),
Text(
"#Doetheman",
style: new TextStyle(
color: Colors.white,
),
),
// Mfer aint appearing
Padding(
padding: const EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 10),
child: Divider(
height: 2.0,
color: Colors.white,
),
),
],
),
),
),
],
),
),
),
),
Widget _buildUserInfo(User user) {
return Column(
children: [
Avatar(
photoUrl: user.photoUrl,
radius: 40,
borderColor: Colors.black54,
borderWidth: 2.0,
),
const SizedBox(height: 8),
if (user.displayName != null)
Text(
user.displayName,
style: TextStyle(color: Colors.white),
),
const SizedBox(height: 8),
],
);
}
}
What I want it to look in view:
enter image description here
Instead of divider you can use container like this
Container(
alignment: Alignment.center,
width: 250,
height: 1,
color: Colors.black
),
Use IntrinsicWidth widget to wrap Column
IntrinsicWidth(
child: Column(
children: [
// ....
Divider(),
],
),
)