Skip to content

Instantly share code, notes, and snippets.

@cristianfb1989
Last active February 27, 2020 22:57
Show Gist options
  • Save cristianfb1989/808a0b5663821b097ba9072535f24bb3 to your computer and use it in GitHub Desktop.
Save cristianfb1989/808a0b5663821b097ba9072535f24bb3 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class ListFirstPage extends StatefulWidget {
@override
_ListFirstPageState createState() => _ListFirstPageState();
}
class _ListFirstPageState extends State<ListFirstPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Page'),
),
body: Column(
children: <Widget>[
GestureDetector(
onTap: () {
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => ListSecondPage()));
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(color: Colors.black, width: 2)),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * .1,
child: Center(
child: Text('List 1',
style: TextStyle(fontSize: 28, color: Colors.black)),
),
),
),
),
GestureDetector(
onTap: () {
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => ListSecondPage()));
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(color: Colors.black, width: 2)),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * .1,
child: Center(
child: Text('List 2',
style: TextStyle(fontSize: 28, color: Colors.black)),
),
),
),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ListSecondPage(
indexRecibido: 9,
)));
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(color: Colors.black, width: 2)),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * .1,
child: Center(
child: Text('List 3',
style: TextStyle(fontSize: 28, color: Colors.black)),
),
),
),
),
],
),
);
}
}
class ListSecondPage extends StatefulWidget {
var indexRecibido;
ListSecondPage({Key key, @required this.indexRecibido}) : super(key: key);
@override
_ListSecondPageState createState() => _ListSecondPageState();
}
class _ListSecondPageState extends State<ListSecondPage> {
ScrollController _controller;
@override
void initState() {
_controller = ScrollController();
super.initState();
_animateToIndex(widget.indexRecibido);
}
_animateToIndex(index) {
_controller.animateTo(1.0 * index,
duration: Duration(seconds: 1), curve: Curves.fastOutSlowIn);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Column(
children: <Widget>[
SizedBox(
height: 500,
child: ListView(
controller: _controller,
children: <Widget>[
Center(
child: Text('List 1', style: TextStyle(fontSize: 30)),
),
Container(
child: Text('Item 1', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 2', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 3', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 4', style: TextStyle(fontSize: 20)),
),
SizedBox(
height: 100,
),
Center(
child: Text('List 2', style: TextStyle(fontSize: 30)),
),
Container(
child: Text('Item 5', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 6', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 7', style: TextStyle(fontSize: 20)),
),
SizedBox(
height: 100,
),
Center(
child: Text('List 3', style: TextStyle(fontSize: 30)),
),
Container(
child: Text('Item 8', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 9', style: TextStyle(fontSize: 20)),
),
Container(
child: Text('Item 10', style: TextStyle(fontSize: 20)),
),
],
)),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment