Skip to content

Instantly share code, notes, and snippets.

@raviganwal
Last active July 6, 2022 20:10
Show Gist options
  • Save raviganwal/05580cdd07f78114d05c702d5993d510 to your computer and use it in GitHub Desktop.
Save raviganwal/05580cdd07f78114d05c702d5993d510 to your computer and use it in GitHub Desktop.
commom dark and light theme
import 'package:flutter/material.dart';
import 'package:verto_india/userauth/EditProfileScreen.dart';
import 'package:verto_india/userauth/VierfyScreen.dart';
import 'package:verto_india/utils/AppColors.dart';
import 'home/MenuDrawer.dart';
import 'home/network/GenealogyScreen.dart';
import 'home/network/Network.dart';
import 'userauth/LoginScreen.dart';
import 'userauth/RegisterScreen.dart';
import 'userauth/SplashScreen.dart';
import 'utils/AppStyles.dart';
void main() {
TextTheme _buildTextTheme(TextTheme base) {
return base.copyWith(
title: base.title.copyWith(
fontFamily: 'opensans',
),
);
}
// Customize your dark theme here
ThemeData _buildDarkTheme() {
final Color primaryColor = AppColors.themeColor;
const Color secondaryColor = Color(0xffff5722);
final ColorScheme colorSchemeDark = const ColorScheme.light().copyWith(
primary: primaryColor,
secondary: secondaryColor,
onPrimary: Colors.white70,
onBackground: Colors.white,
onSurface: AppColors.colorWhite,
onSecondary: AppColors.colorWhite,
secondaryVariant: AppColors.colorSecondaryText,
);
final ThemeData base = ThemeData(
brightness: Brightness.dark,
accentColorBrightness: Brightness.light,
colorScheme: colorSchemeDark,
primaryColor: primaryColor,
primaryColorDark: const Color(0xFF005e9c),
primaryColorLight: secondaryColor,
buttonColor: primaryColor,
indicatorColor: secondaryColor,
toggleableActiveColor: AppColors.themeColor.shade700,
accentColor: AppColors.themeColorSecondary,
canvasColor: AppColors.colorBackgroundDark,
scaffoldBackgroundColor: AppColors.colorBackgroundDark,
backgroundColor: AppColors.colorBackgroundDark,
errorColor: AppColors.colorErrorDark,
hintColor: Colors.white60,
primaryIconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.white),
accentIconTheme: IconThemeData(color: Colors.white),
cursorColor: AppColors.themeColorSecondary,
tabBarTheme: TabBarTheme(
labelColor: Colors.white,
unselectedLabelColor: Colors.white70,
labelStyle: AppStyle.body2,
unselectedLabelStyle: AppStyle.body1,
indicatorSize: TabBarIndicatorSize.tab,
indicator: AppStyle.boxDecorationDark,
),
textTheme: AppStyle.textThemeDark,
accentTextTheme: AppStyle.textTheme,
primaryTextTheme: AppStyle.textTheme,
appBarTheme: AppBarTheme(textTheme: TextTheme(title: AppStyle.titleDark)),
cardTheme: CardTheme(
margin: EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 8),
elevation: 6.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
inputDecorationTheme: InputDecorationTheme(
prefixStyle: TextStyle(fontSize: 14),
errorStyle: TextStyle(fontSize: 10, color: AppColors.colorErrorDark),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
hintStyle: TextStyle(color: Colors.white60, fontSize: 10)),
buttonTheme: ButtonThemeData(
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
colorScheme: colorSchemeDark,
splashColor: AppColors.themeColor.shade900,
height: 50,
highlightColor: AppColors.themeColor.shade800,
textTheme: ButtonTextTheme.primary,
),
);
return base;
}
// Customize your light theme here
ThemeData _buildLightTheme() {
const Color primaryColor = Color(0xFF008FD1);
const Color secondaryColor = Color(0xffff5722);
final ColorScheme colorScheme = const ColorScheme.light().copyWith(
primary: primaryColor,
secondary: secondaryColor,
onPrimary: AppColors.colorWhite,
onBackground: AppColors.colorPrimaryText,
onSurface: AppColors.colorSecondaryText,
onSecondary: AppColors.colorWhite,
secondaryVariant: AppColors.colorSecondaryText,
);
final ThemeData base = ThemeData(
brightness: Brightness.light,
accentColorBrightness: Brightness.dark,
colorScheme: colorScheme,
primaryColor: primaryColor,
buttonColor: primaryColor,
indicatorColor: secondaryColor,
toggleableActiveColor: AppColors.themeColor.shade400,
splashColor: AppColors.themeColor.shade50,
splashFactory: InkRipple.splashFactory,
accentColor: AppColors.themeColorSecondary,
canvasColor: Colors.white,
scaffoldBackgroundColor: Colors.white,
backgroundColor: Colors.white,
errorColor: AppColors.colorErrorLight,
hintColor: AppColors.colorHint,
primaryIconTheme: IconThemeData(color: AppColors.colorWhite),
iconTheme: IconThemeData(color: AppColors.colorWhite),
accentIconTheme: IconThemeData(color: AppColors.colorWhite),
tabBarTheme: TabBarTheme(
labelColor: AppColors.themeColor,
unselectedLabelColor: AppColors.colorWhite,
labelStyle: AppStyle.body2,
unselectedLabelStyle: AppStyle.body1,
indicatorSize: TabBarIndicatorSize.tab,
indicator: AppStyle.boxDecoration,
),
textTheme: AppStyle.textTheme,
accentTextTheme: AppStyle.textTheme,
primaryTextTheme: AppStyle.textTheme,
appBarTheme: AppBarTheme(textTheme: TextTheme(title: AppStyle.titleDark)),
cardTheme: CardTheme(
margin: EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 8),
elevation: 6.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
inputDecorationTheme: InputDecorationTheme(
prefixStyle: TextStyle(fontSize: 14),
errorStyle: TextStyle(fontSize: 10, color: AppColors.colorErrorLight),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
hintStyle: TextStyle(color: Colors.black38, fontSize: 10)),
buttonTheme: ButtonThemeData(
height: 50,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
colorScheme: colorScheme,
splashColor: AppColors.themeColor.shade900,
highlightColor: AppColors.themeColor.shade800,
textTheme: ButtonTextTheme.primary,
),
);
return base;
}
final ThemeData kLightGalleryTheme = _buildLightTheme();
final ThemeData kDarkGalleryTheme = _buildDarkTheme();
runApp(
// Pass dark and light theme in your materialApp
MaterialApp(
theme: kLightGalleryTheme,
darkTheme: kDarkGalleryTheme,
debugShowCheckedModeBanner: false,
title: 'Named Routes Demo',
// Start the app with the "/" named route. In our case, the app will start
// on the FirstScreen Widget
initialRoute: 'SplashScreen',
routes: {
// When we navigate to the "/" route, build the FirstScreen Widget
'SplashScreen': (context) => SplashScreen(),
'LoginScreen': (context) => LoginScreen(),
'RegisterScreen': (context) => RegisterScreen(),
'VierfyScreen': (context) => VierfyScreen(),
'MenuDrawer': (context) => MenuDrawer(),
'GenealogyScreen': (context) => GenealogyScreen(),
'EditProfileScreen': (context) => EditProfileScreen(),
},
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment