How can I create Custom Dark mode? - flutter
I'm trying to make custom dark mode for my app.
Is there a way I set the buttons color, primary color and other themes colors,
then make a button to swap between light and dark mode?
`static get Black => true ? black_1D26 : black1_dark_0x161D;
static get lightviolet => true ? lightviolet_879B :lightviolet_dark_0x9CB1;
static get blue => true ? blue_0x2348FF : blue_dark_0x4B78`;
You could use a ThemeProvider that holds the selected theme and you can implement getter functions inside of the provider
One way is to:
Create a class that contains a ThemeData object.
select items in that object you want to change depends on the theme you selected.
something like this, for primaryColor,
bool lightTheme = true;
primaryColor : lightTheme ? Colors.blue : Colors.red,
find all the properties for ThemeData class below.
ThemeData(
{Brightness? brightness,
VisualDensity? visualDensity,
MaterialColor? primarySwatch,
Color? primaryColor,
Brightness? primaryColorBrightness,
Color? primaryColorLight,
Color? primaryColorDark,
Color? accentColor,
Brightness? accentColorBrightness,
Color? canvasColor,
Color? shadowColor,
Color? scaffoldBackgroundColor,
Color? bottomAppBarColor,
Color? cardColor,
Color? dividerColor,
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? splashColor,
InteractiveInkFeatureFactory? splashFactory,
Color? selectedRowColor,
Color? unselectedWidgetColor,
Color? disabledColor,
Color? buttonColor,
ButtonThemeData? buttonTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
Color? secondaryHeaderColor,
#Deprecated('Use TextSelectionThemeData.selectionColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? textSelectionColor,
#Deprecated('Use TextSelectionThemeData.cursorColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? cursorColor,
#Deprecated('Use TextSelectionThemeData.selectionHandleColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? textSelectionHandleColor,
Color? backgroundColor,
Color? dialogBackgroundColor,
Color? indicatorColor,
Color? hintColor,
Color? errorColor,
Color? toggleableActiveColor,
String? fontFamily,
TextTheme? textTheme,
TextTheme? primaryTextTheme,
TextTheme? accentTextTheme,
InputDecorationTheme? inputDecorationTheme,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
IconThemeData? accentIconTheme,
SliderThemeData? sliderTheme,
TabBarTheme? tabBarTheme,
TooltipThemeData? tooltipTheme,
CardTheme? cardTheme,
ChipThemeData? chipTheme,
TargetPlatform? platform,
MaterialTapTargetSize? materialTapTargetSize,
bool? applyElevationOverlayColor,
PageTransitionsTheme? pageTransitionsTheme,
AppBarTheme? appBarTheme,
ScrollbarThemeData? scrollbarTheme,
BottomAppBarTheme? bottomAppBarTheme,
ColorScheme? colorScheme,
DialogTheme? dialogTheme,
FloatingActionButtonThemeData? floatingActionButtonTheme,
NavigationRailThemeData? navigationRailTheme,
Typography? typography,
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
SnackBarThemeData? snackBarTheme,
BottomSheetThemeData? bottomSheetTheme,
PopupMenuThemeData? popupMenuTheme,
MaterialBannerThemeData? bannerTheme,
DividerThemeData? dividerTheme,
ButtonBarThemeData? buttonBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
TimePickerThemeData? timePickerTheme,
TextButtonThemeData? textButtonTheme,
ElevatedButtonThemeData? elevatedButtonTheme,
OutlinedButtonThemeData? outlinedButtonTheme,
TextSelectionThemeData? textSelectionTheme,
DataTableThemeData? dataTableTheme,
CheckboxThemeData? checkboxTheme,
RadioThemeData? radioTheme,
SwitchThemeData? switchTheme,
bool? fixTextFieldOutlineLabel,
#Deprecated('No longer used by the framework, please remove any reference to it. ' 'This feature was deprecated after v1.23.0-4.0.pre.') bool? useTextSelectionTheme}
)
Related
when identifying an variable color in the class and I cant use it in flutter
when identifying an variable color in the class and I cant use it in flutter what's the the wrong? when identifying an variable color in the class and I cant use it in flutter what's the the wrong?
Colors.white is a type of MaterialColor not Color. Change your variable declaration to MaterialColor backColor = Colors.white, or even better, just write final backColor = Colors.white.
There's a key difference between a materialColor and Color. Change your variable to: Color backColor = const Color(0xFFFFFFFF);
Is there a way to change the outline border color of the OTP fields using PinCodeTextField plugin
I'm new to Flutter. I'm using PinCodeTextField https://pub.dev/packages/pin_code_fields plugin to create OTP Text field I want the text field to be in different color but I couldn't find the decoration property to change the colour.
Spent hours looking for the same problem and finaly found a way around. Searck for a file ‘otp_field_style.dart’ through find. Open the file and you will see following: import 'package:flutter/material.dart'; import 'package:<myApp’s Constants>/constants/constants.dart'; class OtpFieldStyle { /// The background color for outlined box. final Color backgroundColor; /// The border color text field. final Color borderColor; /// The border color of text field when in focus. final Color focusBorderColor; /// The border color of text field when disabled. final Color disabledBorderColor; /// The border color of text field when in focus. final Color enabledBorderColor; /// The border color of text field when disabled. final Color errorBorderColor; OtpFieldStyle( {this.backgroundColor: kFillShade7, this.borderColor: kOrange4, this.focusBorderColor: kOrange1, this.disabledBorderColor: kFillShade4, this.enabledBorderColor: kFillShade2, this.errorBorderColor: Colors.red}); } Now, you can change the colors by giving the hard values, OR Import your constants.dart file (where one normally defines the constants, including colors etc) in this and link the colors through it e.g, import 'package:/constants/constants.dart'; is my contants file, I have linked my kColors in above code, just change it to appropriate link for your constants dart file. 5. Save and close ‘otp_field_style.dart’. You can change the colors through your defined constants, I hope it helps!
you can use this properties to change the colors pinTheme: PinTheme( shape: PinCodeFieldShape.box, borderRadius: BorderRadius.circular(5), fieldHeight: 50, fieldWidth: 40, activeFillColor: Colors.black, inactiveColor: Colors.deepOrange, inactiveFillColor: Colors.green, selectedFillColor: Colors.deepPurple, selectedColor: Colors.greenAccent, activeColor: Colors.blue ),
Why are colours lighter when using my own theme in Flutter?
I have created my own theme in Flutter but when I try to use these colours they are much lighter on the emulator. I'm new to Flutter so I'm not sure of the best way to create a theme but the colours do appear. What is the best way to set your own theme or why would the colours be lighter? import 'package:flutter/material.dart'; extension CustomPrimaryColorScheme on ColorScheme { Color get primaryColor => const Color(0xfffa4659); Color get accentColor => const Color(0xfff0fff3); Color get watermelonLight => const Color(0xffFFF0F1); } extension CustomColorScheme on ColorScheme { Color get aqua =>const Color(0xff11cbd7); Color get paleAqua => const Color(0xffc6f1e7); Color get ice => const Color(0xfff0fff3); Color get watermelon => const Color(0xfffa4659); Color get brownGrey => const Color(0xff979797); Color get charcoal => const Color(0xff313939); } backgroundColor: Theme.of(context).colorScheme.watermelon;
How do I send and/or Receive Colors as argument in Flutter
here is the declaration of 'colour' final Colors colour; this is the method/constructor where I will be receiving a color from my main.dart MyCardState( myQuestion: myQuestion, myColor: colour, opA: myOptionA, opB: myOptionB ) But I have no idea how to send a color from my main.dart. I tried colour: Colors.cyan but it won't work.
You should use the class Color, in singular: class MyCardState { final Color color; MyCardState({this.color}); } Also, keep in mind that some colors in Colors.* are instances of MaterialColor and not Color.
problem solved I was supposed to use final Color colour instead of final Colors colour
FloatingActionButton backgroundColor defaults to accentColor
I have got redirected from https://github.com/flutter/flutter/issues/28138 to here. Generally my problem is that I don´t think that FloatingActionButton backgroundColor and FlatButton text color are inherited from right values defined in ThemeData. Create an app where you will use primary red color (appbar, button bg, card), yellow for accent (icons, appbar title), black for general text, white/light grey for backgrounds like scaffold body. Set AppBar BG color to red using using theme (primaryColor) Set AppBar title color to yellow using theme (accentColor) Set color of icons to same color as accentColor, since if primary color is used they will be invisible in AppBar Create a floatingActionButton with an icon. Icon in floatingActionButton is not visible because backgroundColor for the widget uses the ThemeData.accentColor, which is yellow, instead of the ThemeData.primaryColor Both foreground and background defaults to accentColor. /// The color to use when filling the button. /// /// Defaults to **[ThemeData.accentColor**] for the current theme. final Color backgroundColor; I found similar issue with FlatButton in Dialog, by default color of text is accent color, which is yellow (on white background), if i override it to primary, it´s red, but I don´t want to have it red since the delete button next to it is red. So I need to set it to normal, so it´s black which is correct, but: flat_button.dart:127 textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)), My theme: buttonTheme: ButtonThemeData( textTheme: ButtonTextTheme.normal, buttonColor: primary, // Red ), textTheme: TextTheme( ... button: TextStyle(color: black), // Black ), new FlatButton( //textTheme: ButtonTextTheme.normal, child: new Text("Ponechať"), onPressed: () { Navigator.of(context).pop(); onKeep(); }, ) In theory my FlatButton in the popup dialog should be black and or red. But it´s yellow the accent color. To reproduce try to following example: https://gist.github.com/erikkubica/45fc8acdce1f8a25cd5258e8b3a0e1f3
If you want the color of the floating button to be primary, add the following. floatingActionButton: FloatingActionButton( backgroundColor: Theme.of(context).primaryColor, If you want to change the color of FlatButton in the dialog to black, add the following. theme: ThemeData( colorScheme: ColorScheme.light( primary: primary, secondary: Colors.black, ), It may be better to instantiate it with ColorScheme() so that it does not affect other widgets.