Flutter OutlinedButton with icon ripple color - android

I am trying to use Outlined Button with icon, when if I set a color for the icon, it also changes the ripple effect color.
Widget build(BuildContext context) => Container(
margin: EdgeInsets.symmetric(horizontal: 20),
padding: EdgeInsets.all(4),
child: OutlinedButton.icon(
label: Text(
'Sign In With Google',
style: TextStyle(
color: Colors.black,
fontFamily: "RobotoCondensed",
fontWeight: FontWeight.bold,
fontSize: 16),
),
style: OutlinedButton.styleFrom(
shape: StadiumBorder(),
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
side: BorderSide(width: 1, color: Colors.black),
),
icon: FaIcon(FontAwesomeIcons.google, color: Colors.red),
onPressed: () {
final provider =
Provider.of<GoogleSignInProvider>(context, listen: false);
provider.login();
},
),
);
Can someone help me understand how can I define the ripple color to stay as black?

I don't know if I understood correctly, but try adding foregroundColor in style:
style: OutlinedButton.styleFrom(
...
foregroundColor: Colors.black, //change colour here
),

Related

Change text color of CountryCodePicker widget text in Flutter

From this code, I want to display the country code in white color. The color of the code is set as black as default in its dependencies. Can you tell me how to fix this issue?
ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0),
child: Container(
padding: const EdgeInsets.only(left: 20.0),
child: Form(
key: _formKey,
child: TextFormField(
controller: _controller,
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontFamily: 'Open Sans',
),
decoration: const InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your phone number',
hintStyle: TextStyle(
fontFamily: 'Open Sans',
fontSize: 12,
color: Color(0x80ffffff),
fontWeight: FontWeight.w700,
),
),
validator: (value) {
if (value!.isEmpty ||
!RegExp(r'^[0-9]{12}').hasMatch(value)) {
return " Enter valid Number";
} else {
return null;
}
}),
),
decoration: BoxDecoration(
color: const Color(0x731d192c),
borderRadius: BorderRadius.circular(3.0),
),
),
),
),
),
Pinned.fromPins(
Pin(size: 55.0, start: 42.0),
Pin(size: 48.0, middle: 0.2349),
child:
// Adobe XD layer: 'Rectangle' (shape)
ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0),
child: Container(
decoration: BoxDecoration(
color: Color.fromARGB(115, 255, 255, 255),
borderRadius: BorderRadius.circular(3.0),
),
child: CountryCodePicker(
initialSelection: 'US',
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
favorite: ['+1', 'US'],
enabled: true,
hideMainText: false,
showFlagMain: false,
showFlagDialog: true,
padding: EdgeInsets.all(0.5),
),
),
),
),
),
Here's a screenshot of the text of the country code picker form that I made. I want to change the text color of the number at the left side of the picture where it is generating the country code based on the phone number provided at the right side.
According to the Github repo Customization section of the read me documentation of the CountryCodePicker widget package, you have to add textStyle property to change the color. So, do the following:
textStyle: TextStyle(color: Colors.black),
After updating your CountryCodePicker widget will look like this:
child: CountryCodePicker(
textStyle: TextStyle(color: Colors.black), //After update
initialSelection: 'US',
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
favorite: ['+1', 'US'],
enabled: true,
hideMainText: false,
showFlagMain: false,
showFlagDialog: true,
padding: EdgeInsets.all(0.5),
),
You Just need to set the color property of text which is easy
container(
child: Text(
"+376",
style:TextStyle(
color:Colors.white, /// the color property
color:Color(0xff963258), ///if you want to use HEX color
),
),
),
Note:- You can not use both at the same time

How to outline color an icon but that you can fill the color as well [Flutter]

Hi what I want to do is make a stacked Icons type similar to this example for Text:
Stack(
children: <Widget>[
Text(
widget.news.title,
style: TextStyle(
fontSize: 20,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 2
..color = Colors.black,
),
),
Text(
widget.news.title,
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
],
),
So what my goal is to have an amber colored fill with white outline for backarrow icon (added with SilverAppBar), but for now I was only able to access the iconTheme as follow:
iconTheme: IconThemeData(
color: Colors.white,
),
So my question is as follow: How can I have back arrow icon with SilverAppBar colored that way
Output Image:
The Widget part code:
return <Widget>[
SliverAppBar(
pinned: true,
expandedHeight: 200,
title: Stack(
children: <Widget>[
Text(
widget.news.title,
style: TextStyle(
fontSize: 20,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 2
..color = Colors.black,
),
),
Text(
widget.news.title,
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
],
),
flexibleSpace: FlexibleSpaceBar(
background: Image.network(
widget.news.urlToImage,
fit: BoxFit.fill,
errorBuilder: (context, error, StackTrace) {
return Image(
fit: BoxFit.cover,
image: AssetImage("images/placeholder_details.png"),
);
},
),
),
)
];
Looking forward to hear your opinion :D
Tried out multiple solutions, and this works perfectly.
Use icon_decoration like this:
DecoratedIcon(
icon: Icon(Icons.arrow_back, color: Colors.white),
decoration: IconDecoration(border: IconBorder()),
)

how to center text on an elevated button

I'm trying to center the text on an elevatedbutton but I'm not succeeding. Here's the code:
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blueAccent, // background
textStyle: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
height: 2.8,
),
),
child: Text(
"Add",
),
onPressed: _addToDo,
),
Wrap the Text with a Center widget.
so instead of this:
child: Text(
"Add",
),
do this:
Center(
child: Text(
"Add",
)),
Remove height: 2.8 from style and wrap ElevatedButton with SizedBox and give desire height.
SizedBox(
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blueAccent, // background
textStyle: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
child: Text("Add"),
onPressed: _addToDo,
),
);

How to set rounded corner of TextSpan in Flutter

I want to set rounded corner of Textspan in flutter, I think class Paint is needed, but I cannot figure out how to do that.
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: new AppBar(),
body: new RichText(
text: new TextSpan(
text: null,
style: TextStyle(fontSize: 20.0, color: Colors.black),
children: <TextSpan>[
new TextSpan(
text: 'inactive ',),
new TextSpan(
text: 'active',
style: new TextStyle(
color: Colors.white,
background: Paint()
..color = Colors.redAccent,
)),
],
),
),
),
);
}
}
Is there a way to use Textspan to achieve that instead of using a Container wrapping Text?
Without using Container or something else - I can see only one way to make corners rounded
TextSpan(
text: 'active',
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
background: Paint()
..strokeWidth = 24.0
..color = Colors.red
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round))
But in this case there are paddings around text, so I doubt this is proper way
You can use RichText with WidgetSpan, then combine it with line height
RichText(
text: TextSpan(
children: [
WidgetSpan(
child: Container(
child: Text(
addressItem.deliveryAddressType == "home" ? "Nhà" : "Văn phòng",
style: TextStyle(
fontFamily: AppFonts.SFUITextMedium,
color: AppColors.wram_grey,
fontSize: AppFonts.textSizeSmall,
),
),
decoration: BoxDecoration(
color: AppColors.header_grey, borderRadius: BorderRadius.all(Radius.circular(20))),
padding: EdgeInsets.fromLTRB(6, 2, 6, 2),
margin: EdgeInsets.only(right: 5),
),
),
TextSpan(
text: '${addressItem.street}, ${addressItem.ward}, ${addressItem.city}, ${addressItem.region}',
style: TextStyle(
fontFamily: AppFonts.SFUITextMedium,
color: AppColors.wram_grey,
fontSize: AppFonts.textSizeMedium,
height: 1.5),
),
],
),
),
if the highlighted text is short enough (so you do not want to break line in it), you can just use WidgetSpan insted of TextSpan.
For example:
RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(
text: "some text",
),
WidgetSpan(
child: Container(
padding: EdgeInsets.symmetric(vertical: 1),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(999),
),
child: IntrinsicWidth(
child: Text(
"some text",
),
),
)
),
TextSpan(text: "some text"),
],
),
),
I have created a package which is able to customize the background of the text --> you can change the radius, padding and color for the text background.
It's a fork from the AutoSizeText widget so you could even autosize the text if you want to.
Here is an example image of the text with background, radius and padding.
Hope this can help anyone who needs it.
The link to the github repo is following: https://github.com/Letalus/auto_size_text_background
If you want to set the rounded corner of the text field in Flutter You have to use Container only, If you want to avoid Container then there is another way, you have to avoid using ListView as a body in your app. If you want to add an only single item on screen then you can try without container but if there is more than one item then you have no choice without implementing ListView and add multiple containers for a different purpose.
new Container(
height: 80.0,
color: Colors.transparent,
child: new Container(
decoration: new BoxDecoration(
color: Colors.green,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(30.0),
topRight: const Radius.circular(30.0),
bottomLeft: const Radius.circular(30.0),
bottomRight: const Radius.circular(30.0))),
child: new Center(
child: new Text("Active text"),
)),
),

What is the best way of formatting text in this Flutter example?

I have a card that I tap to toggle DND on or off. On the card, at the moment, I have a string of text that says either "DND ON" or "DND OFF". What I am trying to achieve is to add, below "DND ON", in smaller fontsize and in italics: "Alarms, Media, Touch Sounds".
My bare bones code:
Card(
color: Color.fromARGB(255, 76, 175, 80),
elevation: 5.0,
child: InkWell(
splashColor: Colors.blueGrey,
onTap: () {
setState(() {
pressed = !pressed;
});
pressed ? _dndOn() : _dndOff();
},
child: Center(
child: Text(
pressed ? ('DND ON') : ('DND OFF'),
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
),
),
),
What I have tried: I have tried defining my string in RichText, using TextTheme, and creating a column of text with various styles. Every time I get an error such as "type 'Column' is not a subtype of type 'String'" or "type 'RichText' is not a subtype of type 'String' etc.
Would you have any ideas as to how I could achieve what I want?
You can't use a column widget as the text property of the Text widget. You need to use it in a way where you define the list of children to hold, in this case, the list of Text widgets.
Card(
color: Color.fromARGB(255, 76, 175, 80),
elevation: 5.0,
child: InkWell(
splashColor: Colors.blueGrey,
onTap: () {
setState(() {
pressed = !pressed;
});
pressed ? _dndOn() : _dndOff();
},
child: Center(
child: Column(
children: [
Text(
pressed ? 'DND ON' : 'DND OFF',
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
Text(
'Alarms, Media, Touch Sounds',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
],
),
),
),
),

Categories

Resources