Can I use two ThemeData types? - flutter

I am trying to use these two ThemeData types in my MaterialApp. Check it out:
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'DISH Connect',
home: SiteLayout(),
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
darkTheme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
themeMode: provider.themeMode,
);
You can see that for my normal theme option, I have ThemeData.light(). I want to do the same for dark (which means I have to do 'ThemeData.dark()'). But I also want to be able to declare my pageTransitionTheme for these.
How can I make this possible?

You can use copyWith() method:
darkTheme: ThemeData.dark().copyWith(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),

Related

No MaterialLocalizations found in flutter use GETX

when I tab on input to open datepicker dialog, it was error
Please help me , I use GETX Flutter
This is main.dart
#override
Widget build(BuildContext context) {
GetStorage box = GetStorage();
//print(box.read('lang'));
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
locale: LocalizationService.getLocaleFromLanguage(
langCode: box.read('lang') ?? 'en'),
fallbackLocale: LocalizationService.fallbackLocale,
translations: LocalizationService(),
initialRoute: AppPages.INITIAL,
getPages: AppPages.routes,
);
}

How to change the `primary color` for ThemeData dark in flutter?

I am using flutter 2.8.0 to create a simple app.
But when I am trying to change the primary color for the App it does not work with me.
This is the code I am working on:
class BMICalculator extends StatelessWidget {
const BMICalculator({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
primaryColor: const Color(0xFF0A0E21),
scaffoldBackgroundColor: const Color(0xFF0A0E21),
),
home: const InputPage(),
);
}
}
#Mrinal already mentioned you to use primarySwatch. Flutter team intended to build clean up the Theme system and make everything more consistent and based off of the ColorScheme colors. They recommend using color scheme instead of primary color
theme: ThemeData(
primaryColor: ColorsX.primary,
colorScheme: ColorScheme.light().copyWith(primary: ColorsX.primary),
);
For dark theme
theme: ThemeData.dark().copyWith(
colorScheme: ColorScheme.light().copyWith(primary: Colors.tealAccent),
),
output:
For more read this article article
Use primarySwatch
theme: ThemeData(
primarySwatch: Colors.red,
),
I found a solution for me..
MaterialColor _primartSwatch = Colors.purple;
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
themeMode: _themeMode,
theme: ThemeData(
primarySwatch: _primartSwatch,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
primarySwatch: _primartSwatch,
),
home: SplashScreen(),
);
}

Flutter Page Route Animation

How do I add animation to my existing routes?
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Home',
home: Home(),
onGenerateInitialRoutes: ,
routes: {
SettingsScreen.routeName: (ctx) => SettingsScreen(),
AboutScreen.routeName: (ctx) => AboutScreen(),
},
From what I search so far, it looks like I have to implement onGenerateRoute
Does this mean I have to remove my current routes setting?
Check official docs here: https://api.flutter.dev/flutter/material/PageTransitionsTheme-class.html
Example usage:
return MaterialApp(
title: 'Transitions Page',
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: ZoomPageTransitionsBuilder(),
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
})),
home: MyHomePage(title: 'Some page'),
);

'textSelectionHandleColor' is deprecated and shouldn't be used

in flutter , I have defined my custom theme like this
ThemeData(
...
textSelectionColor: Colors.black,
textSelectionHandleColor: Colors.white,
),
today, after dart update to version v1.23.0-4.0.pre, my code has found this problem.
'textSelectionHandleColor' is deprecated and shouldn't be used. Use TextSelectionThemeData.selectionHandleColor instead. This feature was deprecated after v1.23.0-4.0.pre..
Try replacing the use of the deprecated member with the replacement.
but i have confused that how to use TextSelectionThemeData.
Does someone know how to do it? Thanks!
You have to use textSelectionTheme attribute and set it to TextSelectionThemeData
import 'package:flutter/material.dart';
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
accentColor: Color(0xffBA379B).withOpacity(.6),
primaryColor: Color(0xffBA379B),
textSelectionTheme: TextSelectionThemeData(
selectionColor: Color(0xffBA379B).withOpacity(.5),
cursorColor: Color(0xffBA379B).withOpacity(.6),
selectionHandleColor: Color(0xffBA379B).withOpacity(1),
),
),
home: Home(),
);
}
}
With the New Flutter version using textSelectionHandleColor directly is now deprecated.But Flutter added a new way to access it.
MaterialApp(
title: 'My App',
theme: ThemeData(
primaryColor: Colors.red,
textSelectionTheme: TextSelectionThemeData(
selectionColor: Color(0xff35a19d),
cursorColor: Color(0xff35a19d),
selectionHandleColor: Color(0xff35a19d),
),
),
home: MyWidget(),
);
You can acces like Theme.of(context).textSelectionTheme.selectionHandleColor

How to implement a side-slide close page on the TargetPlatform.android?

Flutter setting TargetPlatform.iOS
new MaterialApp(
title: 'Mian',
theme: new ThemeData(
primarySwatch: Colors.orange,
platform: TargetPlatform.iOS,
)
)
Can skip the close page.
Flutter setting TargetPlatform.android
new MaterialApp(
title: 'Mian',
theme: new ThemeData(
primarySwatch: Colors.orange,
platform: TargetPlatform.android,
)
)
Can‘t skip the close page.
You can do it using CupertinoPageRoute when you push the Widget.
First you have to import cupertino:
import 'package:flutter/cupertino.dart';
Then use the Navigator:
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => YourNewWidgetPage()));
By reading the article I have new answers to update, this way is more friendly.
enter code class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
})),
routes: {
"/": (BuildContext context) =>
MyHomePage(title: 'Flutter Demo Home Page'),
"/two": (BuildContext context) => TwoPage(),
},
);
}
}
Thanks to Arvinth for the article:https://medium.com/flutter-community/page-transitions-using-themedata-in-flutter-c24afadb0b5d