Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter SizeTransition and PageRouteBuilder not working

Tags:

flutter

I am trying to get my list item to expand fullscreen. As per the material recommendation. PageRouterBuilder seems like the way to go, SlideTransition and ScaleTransition both worked well, but SizeTransition doesn't seems to work. When I clicked on the list item, the new page gets displayed straight away. I am expecting it to be clipped at start.

Code below.

Thanks in advance for the help!

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    timeDilation = 10.0;
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(title: new Text("Test Expand")),
      body: ListView(children: <Widget>[
        new ListTile(
            title: new Text("Todo 1"),
            onTap: () {
              _onTap(context, 1);
            }),
        new ListTile(
            title: new Text("Todo 2"),
            onTap: () {
              _onTap(context, 2);
            })
      ]),
    );
  }

  void _onTap(BuildContext context, int i) {
    Navigator.of(context).push(new PageRouteBuilder(pageBuilder:
            (BuildContext context, Animation animation,
                Animation secondaryAnimation) {
          return TaskPage(task: i);
        }, transitionsBuilder: (BuildContext context,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
            Widget child) {
          return new SizeTransition(sizeFactor: animation, child: child);
        }));
  }
}

class TaskPage extends StatelessWidget {
  final int task;

  TaskPage({this.task});

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: new Text("Edit")),
        body: new Text("Task " + task.toString()));
  }
}
like image 685
Phuah Yee Keat Avatar asked Jun 03 '18 19:06

Phuah Yee Keat


People also ask

What is PageRouteBuilder in flutter?

PageRouteBuilder has two callbacks, one to build the content of the route ( pageBuilder ), and one to build the route's transition ( transitionsBuilder ). Note: The child parameter in transitionsBuilder is the widget returned from pageBuilder. The pageBuilder function is only called the first time the route is built.

How do you transition in flutter?

Transition in flutter In general, a transition is nothing but moving an object from one place to another. In flutter, it is also the same but in terms of widgets like container, button, and also pages since everything in flutter is itself a widget.

What is size transition in flutter?

SizeTransition acts as a ClipRect that animates either its width or its height, depending upon the value of axis. The alignment of the child along the axis is specified by the axisAlignment.


1 Answers

The root widget of your page is forced to fill the screen, for a simple reason: Flutter don't know how it should align a route that doesn't actually fill the screen.

So, to simplify things, it justs force a fill.

To solve that simply wrap your root widget into an Align:

PageRouteBuilder(
  transitionsBuilder: (context, animation, __, child) {
    return Align(
      child: SizeTransition(
        sizeFactor: animation,
        child: child,
      ),
    );
  },
),
like image 198
Rémi Rousselet Avatar answered Oct 02 '22 10:10

Rémi Rousselet