Created
April 21, 2019 09:08
-
-
Save vejmartin/311cb41ae1170855905cb7962fc1d7ec to your computer and use it in GitHub Desktop.
Android Rubber Band and Cupertino Transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
pageTransitionsTheme: PageTransitionsTheme( | |
builders: <TargetPlatform, PageTransitionsBuilder>{ | |
TargetPlatform.android: CupertinoPageTransitionsBuilder(), | |
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), | |
}, | |
), | |
), | |
home: ScrollConfiguration( | |
behavior: BounceScrollBehavior(), | |
child: HomePage(), | |
), | |
); | |
} | |
} | |
class BounceScrollBehavior extends ScrollBehavior { | |
@override | |
getScrollPhysics(_) => const BouncingScrollPhysics(); | |
} | |
class HomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter App'), | |
), | |
body: ListView.builder( | |
itemBuilder: itemBuilder, | |
) | |
); | |
} | |
void pushPage(BuildContext context, int index){ | |
final route = MaterialPageRoute( | |
builder: (_) => Page(index: index), | |
); | |
Navigator.of(context).push(route); | |
} | |
Widget itemBuilder(BuildContext context, int index){ | |
return GestureDetector( | |
onTap: () => pushPage(context, index), | |
behavior: HitTestBehavior.opaque, | |
child: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: Text('$index'), | |
), | |
), | |
); | |
} | |
} | |
class Page extends StatelessWidget { | |
Page({Key key, this.index}): super(key: key); | |
final int index; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('$index'), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment