Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6. @override
  7. Widget build(BuildContext context) {
  8. return MaterialApp(
  9. title: 'Flutter Demo',
  10. theme: ThemeData(
  11. primarySwatch: Colors.blue,
  12. ),
  13. home: Scaffold(appBar: AppBar(), body: ListViewBug()),
  14. );
  15. }
  16. }
  17.  
  18. class ListViewBug extends StatefulWidget {
  19. const ListViewBug({Key key}) : super(key: key);
  20.  
  21. @override
  22. _ListViewBugState createState() => _ListViewBugState();
  23. }
  24.  
  25. class _ListViewBugState extends State<ListViewBug> {
  26. List<String> _originalProductList = [
  27. "Product 1",
  28. "Product 2",
  29. "Product 3",
  30. ];
  31.  
  32. List<String> _productList;
  33.  
  34. @override
  35. initState() {
  36. super.initState();
  37. _productList = _originalProductList;
  38. _filtered = false;
  39. }
  40.  
  41. bool _filtered;
  42.  
  43. toggleFilter() {
  44. setState(() {
  45. _filtered = !_filtered;
  46. if (_filtered) {
  47. _productList = _originalProductList.getRange(1, 3).toList();
  48. } else {
  49. _productList = _originalProductList;
  50. }
  51. });
  52. }
  53.  
  54. @override
  55. Widget build(BuildContext context) {
  56. return Wrap(
  57. children: <Widget>[
  58. FlatButton(
  59. child: Text("Toggle filter"), onPressed: () => toggleFilter()),
  60. Container(
  61. child: ListView(
  62. shrinkWrap: true,
  63. children: _productList
  64. .map(
  65. (item) => Chip(
  66. key: Key(item),
  67. label: Text(
  68. item,
  69. ),
  70. ),
  71. )
  72. .toList(),
  73. ),
  74. ),
  75. ],
  76. );
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement