Flutter UI #99: Fun with Navigator Cube Transition in Flutter


Flutter UI #99: Fun with Navigator Cube Transition in Flutter

Tutorial and code of Navigator Cube Transition in Flutter. Copy and paste the below code as per your requirements.

cube_transition_plus: ^2.0.1

import 'package:cube_transition_plus/cube_transition_plus.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      debugShowCheckedModeBanner: false,
      home: const MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    const separator = SizedBox(
      height: 15,
    );
    return const Scaffold(
      body: Sample1(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Center(child: Text('Navigator Cube Transition'),),
      ),
      body: Center(
        child: RaisedButton(
          child: const Text('Next Page'),
          onPressed: () {
            Navigator.of(context).push(
              CubePageRoute(
                enterPage: const Sample1NextPage(),
                exitPage: this,
                duration: const Duration(milliseconds: 900),
              ),
            );
          },
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.brown,
      appBar: AppBar(
        title: const Text('Page 2'),
      ),
      body: Center(
        child: FlutterLogo(
          size: MediaQuery.of(context).size.width / 2,
        ),
      ),
    );
  }
}

Leave a Reply

Your email address will not be published.