You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/animations/lib/src/basics/02_page_route_builder.dart

56 lines
1.4 KiB

// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class PageRouteBuilderDemo extends StatelessWidget {
static const String routeName = '/basics/page_route_builder';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page 1'),
),
body: Center(
child: RaisedButton(
child: Text('Go!'),
onPressed: () {
Navigator.of(context).push<void>(_createRoute());
},
),
),
);
}
}
Route _createRoute() {
return PageRouteBuilder<SlideTransition>(
pageBuilder: (context, animation, secondaryAnimation) => _Page2(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var tween = Tween<Offset>(begin: Offset(0.0, 1.0), end: Offset.zero);
var curveTween = CurveTween(curve: Curves.ease);
return SlideTransition(
position: animation.drive(curveTween).drive(tween),
child: child,
);
},
);
}
class _Page2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page 2'),
),
body: Center(
child: Text('Page 2!', style: Theme.of(context).textTheme.headline4),
),
);
}
}