1
0
mirror of https://github.com/flutter/samples.git synced 2026-03-28 23:32:05 +00:00
Files
samples/animations/lib/src/basics/02_page_route_builder.dart
2021-06-07 16:00:06 -07:00

58 lines
1.5 KiB
Dart

// 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 {
const PageRouteBuilderDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/page_route_builder';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Page 1'),
),
body: Center(
child: ElevatedButton(
child: const 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: const 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: const Text('Page 2'),
),
body: Center(
child: Text('Page 2!', style: Theme.of(context).textTheme.headline4),
),
);
}
}