How To Transition To New Page With Slide Left To Right In Flutter

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

In this post, we shall discuss the page routes transitions in flutter. We will use the PageRouteBuilder method to animate our tradition between two different pages. You will definitely get an illusion of all types of transitions that are possible and you will be able to customize them as well and make your own Custom Transition.

How To Transition To New Page With Slide Left To Right In Flutter

Transition To New Page With Slide Left To Right
Complete Code For  Transition To New Page With Slide Left To Right In Flutter
main.dart

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

void main() => runApp(new MyApp());



class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: SlideTransPages(),
    );
  }
}
class SlideTransPages extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
            title: Text("Slide To Pages Transitions")),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            children: [
              Text('Lorem Ipsum is simply dummy text of the printing '
                  'and typesetting industry. '
                  'Lorem Ipsum has been the industry '
                  'standard dummy text ever since the 1500s, '
                  'when an unknown printer took a galley of '
                  'type and scrambled it to make a type specimen '
                  'book. It has survived not only five centuries,'
                  ' but also the leap into electronic typesetting,'
                  ' remaining essentially unchanged.'),
              SizedBox(height: 20,),
              Center(
                child: RaisedButton(
                  child: Text("Goto New Page"),
                  textColor: Colors.white,
                  color: Colors.pink,
                  onPressed: () {
                    Navigator.of(context).push(
                        CupertinoPageRoute<Null>(builder: (BuildContext context) {
                          return new FirstPage();
                        }));
                  },
                ),
              ),
            ],
          ),
        ));
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            backgroundColor: Colors.orange,
            title: Text("Slide to Pages Transitions")),
        body: Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              RaisedButton(
                child: Text("Goto Another Page"),
                color: Colors.green,
                textColor: Colors.white,
                onPressed: () {
                  Navigator.of(context).push(
                      CupertinoPageRoute<Null>(builder: (BuildContext context) {
                        return new SecondPage();
                      }));
                },
              ),
              RaisedButton(
                child: Text("Goto Back"),
                color: Colors.indigo,
                textColor: Colors.white,
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          ),
        ));
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
            title: Text("Slide to Pages Transitions")),
        body: Center(
          child: RaisedButton(
            child: Text("Goto Back"),
            color: Colors.red,
            textColor: Colors.white,
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ));
  }
}

 

Related Post