Created
June 6, 2020 01:14
-
-
Save brasizza/a05b93bbec069cdb57999fba81c08d04 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/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
const MyWidget({Key key}) : super(key: key); | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
int currTab = 0; | |
int altura = 20; | |
int totalItens = 30; | |
int totalAbas = 5; | |
ScrollController _scrollController; | |
double jump; | |
@override | |
void initState() { | |
super.initState(); | |
_scrollController = ScrollController() | |
..addListener(() { | |
print("offset = ${_scrollController.offset}"); | |
currTab = (_scrollController.offset) ~/ (totalItens * altura); | |
print(currTab); | |
setState(() {}); | |
}); | |
} | |
@override | |
void dispose() { | |
_scrollController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
for (int i = 0; i < totalAbas; i++) | |
GestureDetector( | |
onTap: () { | |
print(jump.toString()); | |
jump = ((i) * (totalItens*altura)).toDouble(); | |
_scrollController.jumpTo(jump); | |
}, | |
child: Container( | |
decoration: new BoxDecoration( | |
color: i == currTab ? Colors.red : Colors.blue, | |
borderRadius: | |
new BorderRadius.all(Radius.circular(10.0))), | |
width: 100, | |
child: Text( | |
"ABA " + i.toString(), | |
style: TextStyle(color: Colors.white), | |
textAlign: TextAlign.center, | |
))) | |
], | |
), | |
Expanded( | |
child: ListView( | |
controller: _scrollController, | |
children: <Widget>[ | |
for (int i = 0; i < totalItens; i++) | |
Container( | |
height: altura.toDouble(), child: Text("Conten at 0 -" + i.toString())), | |
for (int i = 0; i < totalItens; i++) | |
Container( | |
height: altura.toDouble(), child: Text("Conten at 1 -" + i.toString())), | |
for (int i = 0; i < totalItens; i++) | |
Container( | |
height: altura.toDouble(), child: Text("Conten at 2 -" + i.toString())), | |
for (int i = 0; i < totalItens; i++) | |
Container( | |
height: altura.toDouble(), child: Text("Conten at 3 -" + i.toString())), | |
for (int i = 0; i < totalItens; i++) | |
Container( | |
height: altura.toDouble(), child: Text("Conten at 4 -" + i.toString())), | |
], | |
)), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment