How to make a flare animation fullscreen in flutter? - flutter

I recently made an animation using Flare.
I used flare_splash_screen package to use that animation as a splash screen in my flutter app.
The problem I am facing is that I am unable to make the animation full screen on devices with notches and bezel-less displays.
The animation appears fullscreen on devices like Google Pixel XL and iPhone SE. but not on devices like iPhone 11 Pro, iPhone 11 Pro Max.
The size of my ArtBoard is 1080x1920
I have tried everything like
Using Expanded
Playing with weight and height
Using a container and resizing that
but no matter what I do the animation is in the middle of display and never fullscreen.
any help would be truly appreciated
Here is my code :
class Animation extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SplashScreen.navigate(
name: 'assets/animations/mablac_attire.flr',
next: (_) => AttireScreen(),
until: () => Future.delayed(Duration(
seconds: 1,
milliseconds: 45,
)),
startAnimation: 'Opening',
);
}
}

Related

SOLUTION - SystemUi Overlay Disappearing Using YoutubePlayerFlutter

If this happens when you after you go into full screen.
Before clicking fullscreen
When in fullscreen
Overlay gone on page
Overlay also gone on other pages
Then you will need to add
onExitFullScreen: () => SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: SystemUiOverlay.values),
just under YoutubePlayerBuilder.
Widget build(BuildContext context) {
return YoutubePlayerBuilder(
onExitFullScreen: () => SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: SystemUiOverlay.values),
player: YoutubePlayer(controller: _ytController),
builder: (context, player) {
return Coumn(
children: [
Container(),
player,
]),
});
}
Apologies if this is not a through guide. I spent ages trying to find the problem that when I figured it out I thought id share as I couldn't find it myself online.
Let me know where you need me to clarify more and id be happy to flesh out more details.
Posted above. The reason this works is because YoutubePlayerFlutter removes the System UI when it enters fullscreen mode but it does not correctly add it back once leaving fullscreen mode.
If you have no need for the UI being removed in the Fullscreen mode then instead place the () => SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: SystemUiOverlay.values), under onEnterFullScreen: instead of onExitFullScreen:

Should I create 3 different widgets for each page/screen of my app to be able to run on different size screens?

I am trying to work on a project that should be run on web, tablet and mobile platforms. I think there are 2 approaches to do this:
1- Create 3 different widgets for each page of the app. For example:
import 'package:flutter/material.dart';
class ResponsiveLayout extends StatelessWidget {
final Widget mobileBody;
final Widget tabletBody;
final Widget desktopBody;
ResponsiveLayout({
required this.mobileBody,
required this.tabletBody,
required this.desktopBody,
});
#override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < 500) {
return mobileBody;
} else if (constraints.maxWidth < 1100) {
return tabletBody;
} else {
return desktopBody;
}
},
);
}
}
2- Create only one widget for each screen but check the screen size like mediaquery.of(context).size.width whenever I want to show something differently on web than mobile or table.
I don't know there is also a third approach or which approach is better for big application/projects?
You might want to check out this package:
https://pub.dev/packages/sizer
It is very helpful when working for multiple screen sizes.
From their README:
h - Returns a calculated height based on the device
.w - Returns a calculated width based on the device
.sp - Returns a calculated sp based on the device
SizerUtil.orientation - for screen orientation portrait or landscape
SizerUtil.deviceType - for device type mobile or tablet
Basically, these are 2 ways to handle it.
The tradeoffs here are complexity, flexibility, speed of development and consistency:
if you create 3 separate widgets, you might need to spend more time to preserve consistency (copy code changes between widgets) sometimes, but each widget would be more or less simple to understand.
if you use MediaQuery.of(context) and all the changes automatically propagate to all the versions (which might be a good or a bad thing) and it's way more flexible (i.e. you can show/hide/change some parts of the widget at width < 500 and others at width < 1200), but the code might slowly turn into an unreadable mess.
Here's more info in the official doc

Page Transition is not working specifically scale or fade functions

I am using animated splash screen, but my page transition does not working.
Widget build(BuildContext context) {
return AnimatedSplashScreen(
splash: Image.asset(
'lib/logo/MedicteLogo-4a2e31cd2358bb08ff8d12acb2761357.png'),
nextScreen: HomePage(),
splashTransition: SplashTransition.scaleTransition,
pageTransitionType: PageTransitionType.topToBottomJoined,
);
}
try import this code. I succeeded after importing the code
import 'package:page_transition/page_transition.dart';
I'm also having the same problem here "PageTransition" is not working at all, after duration of splash screen finishes it removes splash screen without an PageTransition and shows next screen.
I think it has something to do with my Android version which is Android 12

Splash screen to Home screen navigation - Flutter

I'm working on a Flutter app and have decided to introduce a splash screen in the same. To navigate to the home screen from the splash screen, normally we use Navigator. But there is one issue that I find in the Navigator method. Whenever i'm popping or pushing a screen, there is a visible navigation, i.e. I can see the screen moving left, right, up or down. What I want to achieve, is that the splash screen should disappear instead of sliding away from the screen. How can I achieve this?
You have to add native splash screen, if you don't want that visible navigation. To add splash screen in your app properly. Please follow the guide: Creating native splash screen
If you are feeling lazy, you can just use the following package : Splash Screen Package. This package is easy to use just read the documentation before installing.
You can use this package flutter_native_splash: ^2.0.5
This package will provide you native splash screen for your apps.
But if you want to disappear your current screen and go to next screen you can use this class custom_route.dart. This class provide you an animation like disappear.
import 'package:flutter/material.dart';
class FadePageRoute<T> extends MaterialPageRoute<T> {
FadePageRoute({
required WidgetBuilder builder,
RouteSettings? settings,
}) : super(
builder: builder,
settings: settings,
);
#override
Duration get transitionDuration => const Duration(milliseconds: 600);
#override
Widget buildTransitions(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
if (settings.name == "/auth") {
return child;
}
return FadeTransition(
opacity: animation,
child: child,
);
}
}
and finally
onPressed: () {
Navigator.of(context).push(FadePageRoute(
builder: (context) => YourScreen(),
));
},

Flutter: Is it possible to auto-scale (whole) ui based on device size?

iOS native apps auto-scale the whole ui based on device size (width). Is there a similar behaviour with flutter?
I want to design a ui (with font sizes, paddings, etc) for a master device (iphone xs) and scale the whole ui to all other devices.
Wondering if that is possible as i couldn't find any information about it.
Just responsive sizing that needs me to configure breakpoints etc.
I usually obtain device size on Widget build, and then use a fraction of the width and height for each widget: Something like this:
import 'package:flutter/material.dart';
Size deviceSize;
class Welcome extends StatefulWidget {
WelcomeState createState() => WelcomeState();
}
class WelcomeState extends State<Welcome> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
deviceSize = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: color3,
body: Container(
height:deviceSize.height*0.5,
width:deviceSize.width-50.0,
child: Text("Welcome"),
),
);
}
}
Yes, this indeed is possible. All you need is a ratio-scaling approach with which you scale your entire GUI. Check out this ratio-scaling solution given to another SO answer relating to the Flutter UI scaling issue.
It's better to use MediaQuery.of(context).size, because while using external package, you won't be able to maintain the size of widgets on orientation change which might be a big downfall if your application required orientation change for better visual effects:
Widget build(BuildContext context) {
AppBar appBar = AppBar(title: const Text("My Dashboard"));
height = MediaQuery.of(context).size.height -
appBar.preferredSize.height -
MediaQuery.of(context).padding.top; // for responsive adjustment
width = MediaQuery.of(context).size.width; // for responsive adjustment
debugPrint("$height, width: ${MediaQuery.of(context).size.width}");
return Scaffold(appBar: appBar, body: ResponsivePage(height,width));
}
Check out this package:
https://pub.dev/packages/scaled_app
Replace runApp with runAppScaled, the entire UI design will be scaled automatically.
Helpful when you want adapt to different screen sizes quickly