Wednesday, June 26, 2024
Google search engine
HomeWidgetsCupertinoPageTransition In Flutter

CupertinoPageTransition In Flutter

Learn how to use Cupertino Page-Transition in your Flutter Apps

Whenever you will code for building anything in Flutter, it will be inside a widget. The central design is to build the application out of widgets. It portrays how your application view ought to look with its current design and state. Right when you made any adjustment in the code, the widget alters its depiction by working out the differentiation between the past and current widget to choose the immaterial changes for conveying in the UI of the application.

In Flutter, to build any application, we start with widgets. The construction block of flutter applications. Widgets portray what their view should look like given their current setup and state. It consolidates a text widget, line widget, segment widget, container widget, and some more.

Navigating between routes is very quite default. Flutter benevolently gives you the MaterialPageRoute and CupertinoPageRoute classes and, while their transition animations don’t look awful, there’s surely something more we can do.

In this article, we will explore the CupertinoPageTransition In Flutter. We will implement the Cupertino page transition demo program and learn how to use the same in your flutter applications.

CupertinoPageTransition class – cupertino library – Dart API
API docs for the CupertinoPageTransition class from the Cupertino Library, for the Dart programming language.api.flutter.dev

If you’re looking for the best Flutter app development company for your mobile application then feel free to contact us at — support@flutterdevs.com.


Table Of Contents::

Cupertino Page Transition

Constructor

Properties

Code Implement

Code File

Conclusion

GitHub Link



CupertinoPageTransition:

It is a widget that provides an iOS-style page transition animation. The page slides in from the right and exits backward. It likewise moves to one side in a parallax motion when another page enters to cover it.

Demo Module :

This demo shows how the transition works in an app. It shows how the page transitions from right to left just like your transition to another page on a device running on iOS/Android.

Constructor:

To utilize CupertinoPageTransition, you need to call the constructor underneath:

CupertinoPageTransition({
Key key,
@required Animation<double> primaryRouteAnimation,
@required Animation<double> secondaryRouteAnimation,
@required Widget child,
@required bool linearTransition,
});

In Above Constructor all fields marked with @required must not be empty.

Properties:

There are some properties of CupertinoPageTransition:

  • > Widget Child: The widget below this widget in the tree. Child Property will have only one child.
  • > Animation<double> primaryRouteAnimation: primaryRouteAnimation is a linear route animation from 0.0 to 1.0 when this screen is being pushed.
  • > Animation<double> secondaryRouteAnimation: secondaryRouteAnimation is a linear route animation from 0.0 to 1.0 when another screen is being pushed on top of this one.
  • > bool linearTransition: linear transition is whether to perform the transitions linearly. Used to precisely trackback gesture drags.

How to implement code in dart file:

You need to implement it in your code respectively:

Create a new dart file called main.dart inside the lib folder.

First, we will make a screen that will show the underlying page and a picture in the center that has an on-tap function which will set off the transition. Then we will make a subsequent page and set it up with another picture, then we want to set up a route style which will be the Cupertino page transition widget.

Center(
child: InkWell(
onTap: () => Navigator.of(context).push(PageTwo.route()),
child: Image.asset('assets/pencil.png'),
),
),

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Initial Screen

With the help of this route property, we will transact from the initial page to the final page with a transition style straight from iOS.

static Route<dynamic> route() {
return CupertinoPageRoute(
builder: (BuildContext context) {
return const PageTwo();
},
);
}

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Final Output

Code File:

import 'package:flutter/cupertino.dart' show CupertinoPageRoute;
import 'package:flutter/material.dart';

void main() {
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
home: Splash(),
),
);
}

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text('Flutter CupertinoPageTransition Demo'),
backgroundColor: Colors.teal,
),
body: Center(
child: InkWell(
onTap: () => Navigator.of(context).push(PageTwo.route()),
child: Image.asset('assets/pencil.png'),
),
),
);
}
}

class PageTwo extends StatelessWidget {
const PageTwo({Key? key}) : super(key: key);

static Route<dynamic> route() {
return CupertinoPageRoute(
builder: (BuildContext context) {
return const PageTwo();
},
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Image.asset('assets/logo.png'),
),
);
}
}

Conclusion:

In the article, I have explained the essential construction of the CupertinoPageTransition widget in a flutter; you can alter this code as indicated according to your choice. This was a little prologue to the CupertinoPageTransition widget on User Interaction from my side, and its functioning utilizing Flutter.

I hope this blog will provide you with sufficient information on Trying up the CupertinoPageTransition widget in your flutter projects. We showed you what the CupertinoPageTransition widget is?, its constructor, and the properties of the CupertinoPageTransition widget. We made a demo program for working CupertinoPageTransition widget, and it shows transitions directly from the iOS/Android in your flutter application. So please try it.

❤ ❤ Thanks for reading this article ❤❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.


GitHub Link:

find the source code of thecupertino_page_transition:

GitHub – flutter-devs/cupertino_page_transition
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…github.com


Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments