Last active
September 15, 2018 18:24
-
-
Save abacaj/dabe0948d0b070306881e69a8a11d0c5 to your computer and use it in GitHub Desktop.
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_slidable/flutter_slidable.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MaterialApp( | |
title: 'Navigation Basics', | |
home: FirstScreen(items: List<String>.generate(40, (i) => "Item $i")), | |
)); | |
} | |
class FirstScreen extends StatefulWidget { | |
final List<String> items; | |
FirstScreen({@required this.items}); | |
@override | |
FirstScreenState createState() => FirstScreenState(); | |
} | |
class FirstScreenState extends State<FirstScreen> { | |
void addNextView(cxt) async { | |
await Navigator.push(cxt, MaterialPageRoute( | |
builder: (_) => SecondScreen(), | |
settings: RouteSettings(name: '/nextView', isInitialRoute: false) | |
)); | |
} | |
@override | |
Widget build(BuildContext context) { | |
print("building list"); | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('First Screen'), | |
actions: <Widget>[ | |
FlatButton( | |
color: Colors.black, | |
onPressed: (){ | |
this.addNextView(context); | |
}, | |
child: | |
Text("Click here to add next view", style: TextStyle(color: Colors.white)) | |
) | |
], | |
), | |
body: | |
Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: [ | |
Container( | |
child: Text("Label") | |
), | |
Flexible(child: ListView.builder( | |
primary: false, | |
physics: BouncingScrollPhysics(), | |
itemCount: widget.items.length, | |
itemBuilder: (context, index) { | |
return Slidable( | |
key: Key(index.toString()), | |
delegate: SlidableBehindDelegate(), | |
actionExtentRatio: 0.2, | |
child: Container( | |
height: 90.0, | |
child: Text('${widget.items[index]}') | |
), | |
showAllActionsThreshold: 0.35, | |
secondaryActions: <Widget>[ | |
SlideAction( | |
onTap: () => {}, | |
color: Color.fromRGBO(51, 217, 178,1.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Icon(Icons.add_circle, color: Color.fromRGBO(33, 140, 116,1.0)), | |
Padding( | |
padding: EdgeInsets.only(top: 5.0), | |
child: Text("Queue", style: TextStyle(fontWeight: FontWeight.w500, color: Color.fromRGBO(33, 140, 116,1.0))) | |
) | |
] | |
) | |
) | |
], | |
); | |
}, | |
)) | |
] | |
) | |
); | |
} | |
} | |
class SecondScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Second Screen"), | |
), | |
body: Center( | |
child: RaisedButton( | |
onPressed: () { | |
Navigator.pop(context); | |
}, | |
child: Text('Go back!'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment