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

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

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(),
);
}

MaterialApp's theme primary color doesn't work

On this flutter sample secondary color works fine but primary color doesn't seem to work why is that?
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final ThemeData theme = ThemeData();
return MaterialApp(
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(
primary: Colors.blue,
secondary: Colors.orange,
)
),
home: MyHomePage(),
);
}
}
Try this
theme: ThemeData( primaryColor: Colors.lightBlue[800], accentColor: Colors.yellow, ),
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final ThemeData theme = ThemeData();
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.blue,
).copyWith(
secondary: Colors.green,
),
home: MyHomePage(),
));
}
}

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'),
);

Change application's starting dart file in flutter

I am new for flutter and I want to change the starting UI(interface). I tried to find out . but could not do it
Here the home: parameter specifies the starting page. If you want to change the page that will open at startup, you can give the name of the page you want instead of HomePage ().
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Time Tracker',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
),
);
}
}
So:
home: HomePage(),
Change to:
home: AnythingPage()