Last active
February 16, 2020 14:03
-
-
Save t-artikov/d0860cb51983297c797cc8f7deb2615e to your computer and use it in GitHub Desktop.
Flutter Touch Detection
This file contains hidden or 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() { | |
final app = MaterialApp( | |
home: MyHomePage(), | |
); | |
runApp(app); | |
} | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
appBar: AppBar( | |
title: Text('Touch Detection Test'), | |
), | |
body: ListView.builder( | |
itemCount: 20, | |
itemBuilder: (context, index) { | |
return Item(index); | |
}, | |
), | |
); | |
} | |
} | |
class Item extends StatelessWidget { | |
final int index; | |
const Item(this.index); | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
_buildContent(context), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: List<Widget>.generate(5, (int i) => _buildStar()), | |
), | |
], | |
); | |
} | |
Widget _buildContent(BuildContext context) { | |
return Container( | |
color: Colors.grey[200], | |
child: Text( | |
'$index. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.', | |
), | |
); | |
} | |
Widget _buildStar() { | |
return SizedBox( | |
width: 20, | |
height: 20, | |
child: Material( | |
color: Colors.yellow, | |
child: InkWell( | |
onTap: () { | |
print('Tapped'); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment