Skip to content

Instantly share code, notes, and snippets.

@tiagolpadua
Created August 12, 2020 14:49
Show Gist options
  • Save tiagolpadua/80d8d238bdea61365b3b480a3f299484 to your computer and use it in GitHub Desktop.
Save tiagolpadua/80d8d238bdea61365b3b480a3f299484 to your computer and use it in GitHub Desktop.
Animated Route Challange
import 'package:bytebank/screens/transactions/list.dart';
import 'package:flutter/material.dart';
import 'contacts/list.dart';
class Dashboard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dashboard'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset('images/bytebank_logo.png'),
),
Container(
height: 120,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
_FeatureItem(
'Transfer',
Icons.monetization_on,
onClick: () {
_showContactsList(context);
},
),
_FeatureItem(
'Transaction Feed',
Icons.description,
onClick: () => _showTransactionsList(context),
),
],
),
),
],
),
);
}
// void _showContactsList(BuildContext context) {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => ContactsList(),
// ),
// );
// }
void _showContactsList(BuildContext context) {
Navigator.of(context).push(_createAnimatedRoute(ContactsList()));
}
_showTransactionsList(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TransactionsList(),
),
);
}
}
class _FeatureItem extends StatelessWidget {
final String name;
final IconData icon;
final Function onClick;
_FeatureItem(
this.name,
this.icon, {
@required this.onClick,
}) : assert(icon != null),
assert(onClick != null);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
color: Theme.of(context).primaryColor,
child: InkWell(
onTap: () => onClick(),
child: Container(
padding: EdgeInsets.all(8.0),
width: 150,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(
icon,
color: Colors.white,
size: 24.0,
),
Text(
name,
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
],
),
),
),
),
);
}
}
Route _createAnimatedRoute(Widget page) {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = Offset(1.0, 1.0);
var end = Offset.zero;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment