how to remove text field cursor bubble in flutter - flutter

How to remove this bubble in flutter while typing in the text field. Any solution for this?

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
textSelectionTheme: TextSelectionThemeData(
selectionHandleColor: Colors.transparent,
),
),
home: Scaffold(body: Center(child: TextField())),
);
}
}

TextField set enableInteractiveSelection property to false can resolve this issue.
enableInteractiveSelection: true,

You will have to change the theme property to change the color of the cursor bubble.
In your theme change the textSelectionHandleColor to transparent . Like this.
Theme(
data: Theme.of(context).copyWith(
textSelectionHandleColor: Colors.transparent,
),

Related

Globally remove all drop shadows in Flutter app?

Is there a way to globally remove all drop shadows in Flutter app?
I would like to do that in single place instead of setting elevation: 0 for all MaterialButtons, ElevatedButtons, etc.
I would like set theme, or do it another way, but globally in single palce.
I was looking for attributes in ThemeData, but can't find desired attributes, e.g. for MaterialButtons.
You were on the right track, ThemeData has an attribute for ElevatedButtons, i have made a small example on what you need to remove shadows based on MaterialStateProperty:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
//this is the function that deletes shadows
double getElevation(Set<MaterialState> states) {
return 0;
}
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light().copyWith(
//this is the property that affects elevated buttons
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
elevation: MaterialStateProperty.resolveWith(getElevation)))),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
//this button doesn't have a shadow
return ElevatedButton(
child: const Text("HEY!"),
onPressed: () {},
);
}
}
The solution is pretty straightforward,
ThemeData(
shadowColor: Colors.transparent,
);
gets the job done

Change color of CircularProgressIndicator and LinearProgressIndicator

Is it possible to change color of CircularProgressIndicator and LinearProgressIndicator to accent color with theme of MaterialApp globally?
(In previous version of flutter the default color was accent color and after upgrading flutter it's primary color)
Try the following code in dart pad, I want to change color of progress globally without chaining primarySwatch if possible
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
accentColor: Colors.red,
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
),
);
}
}
By wrapping with ProgressIndicatorTheme we can customize the color of CircularProgressIndicator and LinearProgressIndicator globally

CupertinoDynamicColor not working for text style within a theme in Flutter

Currently I've got a problem with the dark mode for iOS in Flutter. I'm using a CupertinoApp with a CupertinoTheme.
With CupertinoDynamicColor.withBrightness() it's possible to define colors for dark and light theme. This is working for example for the navigation bar (barBackgroundColor), but not for the textTheme.
Someone already ask a similar question in the flutter repository but I don't know how to do this with a theme. Maybe you can help me there.
Example code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
theme: CupertinoThemeData(
barBackgroundColor: const CupertinoDynamicColor.withBrightness(
color: Colors.blue,
darkColor: Colors.red,
),
textTheme: CupertinoTextThemeData(
textStyle: TextStyle(
color: const CupertinoDynamicColor.withBrightness(
color: Colors.blue,
darkColor: Colors.red,
),
),
),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text('Test')),
child: Text('Test Text'),
);
}
}

I don't understand the point of the Theme class in Flutter

So I was working with Flutter and I needed a custom Widget for a ListView where every widget has its own theme based on some data.
The proper way to do it seems to be something like this:
class CustomWidget extends StatefulWidget {
CustomWidget({Key key, this.data}) : super(key: key);
final Color data;
#override
_CustomWidgetState createState() => _CustomWidgetState();
}
class _CustomWidgetState extends State<CustomWidget> {
#override
Widget build(BuildContext context) {
return Theme(
data: ThemeData(primaryColor: widget.data),
child: Builder(builder: (context) {
return Container(
color: Theme.of(context).primaryColor,
);
}),
);
}
}
But if I do it like this, what exactly is the advantage of this?
Specifically applying the color in the container? Why can't I just do color: widget.data?
Wouldn't it make more sense if things like TextTheme automatically applied to every Text() decadence of Theme()?
The ThemeData is used to configure a Theme or MaterialApp widget:
https://api.flutter.dev/flutter/material/ThemeData-class.html
The primaryColor value does not affect the color of the Text widget, from the docs:
The background color for major parts of the app (toolbars, tab bars, etc)
If you want to change the color of the text then you can use the textTheme property:
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
accentColor : Colors.black,
textTheme: TextTheme(bodyText2: TextStyle(color: Colors.purple)),
primaryColor : Colors.black
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
primaryColor: is used for the appbar
accentColor: is used to color the foreground
textTheme: will change the color of the text and style it
working example:
https://dartpad.dartlang.org/bba537def9dbfa771400309a4e6415ed

How to change color of CircularProgressIndicator

How can I change the color of CircularProgressIndicator?
The value of the color is an instance of Animation<Color>, but I am hoping there is a simpler way to change the color without trouble of the animation.
This worked for me:
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.white))
Three way to solve your problem
1) Using valueColor property
CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(Colors.blue),
),
2) Set accentColor in your main MaterialApp widget.
This is best way because you dont want to set color all the time when you use CircularProgressIndicator widget
MaterialApp(
title: 'My App',
home: MainPAge(),
theme: ThemeData(accentColor: Colors.blue),
),
3) Using Theme Widget
Theme(
data: Theme.of(context).copyWith(colorScheme: ColorScheme(
primary: Colors.red,
// You should set other properties too
)),
child: new CircularProgressIndicator(),
)
for a sigle color set,
CircularProgressIndicator(
valueColor:AlwaysStoppedAnimation<Color>(Colors.red),
);
for multi color change/set.
class MyApp extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyApp> with TickerProviderStateMixin {
AnimationController animationController;
#override
void dispose() {
// TODO: implement dispose
super.dispose();
animationController.dispose();
}
#override
void initState() {
super.initState();
animationController =
AnimationController(duration: new Duration(seconds: 2), vsync: this);
animationController.repeat();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Color Change CircularProgressIndicator"),
),
body: Center(
child: CircularProgressIndicator(
valueColor: animationController
.drive(ColorTween(begin: Colors.blueAccent, end: Colors.red)),
),
),
);
}
}
accentColor can be used for foreground color of Widgets.It changes the color any foreground widgets including circularprogressbar You can use like this:
void main() => runApp(
MaterialApp(
title: 'Demo App',
home: MainClass(),
theme: ThemeData(accentColor: Colors.black),
),
);
backgroundColor set light color it saw like light background color on the circle, valueColor it is loading color it will show compile loading circle over the gray color
CircularProgressIndicator(
backgroundColor: Colors.gray,
valueColor: AlwaysStoppedAnimation<Color>(Colors.black)
)
A theme is a widget that you can insert anywhere in your widget tree.
It overrides the current theme with custom values
Try this:
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
reference: https://gitter.im/flutter/flutter?at=5a84cf9218f388e626a51c2d
valueColor:new AlwaysStoppedAnimation<Color>(Colors.yellow),
Using progressIndicatorTheme allows to define a theme for progress indicator.
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(color: Colors.white),
)
accentColor is deprecated and no longer works.
To have it globally in ThemeData, set it like this:
LIGHT THEME:
theme: ThemeData(
colorScheme: ColorScheme.dark(
primary: Colors.pink,
),
),
DARK THEME:
theme: ThemeData(
colorScheme: ColorScheme(
primary: Colors.pink,
),
),
LOCALLY:
Or if you want it only for that one widget locally, just set the property of the CircularProgressIndicator like this:
CircularProgressIndicator(
backgroundColor:Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(Colors.pink),
),
By default, it inherits accentColor from Themedata
void main() => runApp(new MaterialApp(
theme: ThemeData(
primaryColor: Colors.blue,
accentColor: Colors.blueAccent,
//This will be the color for CircularProgressIndicator color
),
home: Homepage()
));
You can change this accentColor property with your new color.
Other way is using with predefined ThemeData like this
void main() => runApp(new MaterialApp(
theme: ThemeData.light().copyWith(
accentColor: Colors.blueAccent,
//change the color for CircularProgressIndicator color here
),
home: Homepage()
));
Or else you can directly change this color property in CircularProgressIndicator as shown below
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
),
In main.dart set the theme accentColor, the CircularProgressIndicator will use that color
void main() => runApp(new MaterialApp(
theme: ThemeData(primaryColor: Colors.red, **accentColor: Colors.yellowAccent**),
debugShowCheckedModeBanner: false,
home: SplashPage()
));
just write this code in your theme data of your app
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(
color: Colors.grey.shade700,),)
If you want to change it globally, in latest version of flutter you should change colorScheme:
void main() => runApp(
MaterialApp(
title: 'App',
home: Home(),
theme: ThemeData(
colorScheme: ColorScheme(
primary: Colors.red,
// You should set other properties too
)
),
),
);
Use like this--->
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation(Colors.grey[500]),)),
CircularProgressIndicator(
backgroundColor: Colors.amberAccent,
semanticsLabel: 'Linear progress indicator',
),
Try this:
CircularProgressIndicator(
color: Colors.yellow, // Change your color here
),
<com.google.android.material.progressindicator.CircularProgressIndicator app:indicatorColor="#color/primaryColor" />