I want to create button like this in flutter.
Ok I know that text1 and text2 must to be in a Row().
I don’t know to to create this align to text1 must to be in center and text2 must to be align to right.
Image of what I want to create
My code
import 'package:flutter/material.dart';
import 'package:streeti/static/static_colors.dart';
class ButtonWithBlue extends StatelessWidget {
const ButtonWithBlue({Key? key, required this.text1, required this.text2})
: super(key: key);
final String text1;
final String text2;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(20)),
child: Container(
height: 75,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white12,
border: Border.all(
color: AppColors.BlueColor,
width: 1.0,
),
),
child: RawMaterialButton(
onPressed: () {},
splashColor: Colors.blue,
child: Stack(
children: [
Positioned(
right: -20,
top: -25,
height: 120,
width: 120,
child: Container(
decoration: ShapeDecoration(
color: AppColors.BlueColor,
shape: const CircleBorder(),
),
),
),
Container(
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
text1,
style: TextStyle(color: Colors.black, fontSize: 18),
),
SizedBox(
width: 8), // Add some space between text1 and text2
Text(
text2,
style: TextStyle(color: Colors.black, fontSize: 18),
),
],
),
),
],
),
),
),
),
);
}
}
How to build this button so that text1 is in the middle and text2 is on the right? (like on image)
As I wrote, I know that I should use Row() but I don’t know how to do it in this case.
SpaceBettwen + center?
3
Answers
H!, you can use Spacer()
Also so that the blue edges do not get cut off you have to add to container that is inside ClipRRect:
The default
mainAxisSize: MainAxisSize.max
on Row, you can useAlso you can just use string like
Text('$text1 $text2')
orText.rich
.One way is to use Stack and align Texts to
center
andcenterRight
. Something like this: