Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: Scaffold(appBar: AppBar(), body: ListViewBug()),
- );
- }
- }
- class ListViewBug extends StatefulWidget {
- const ListViewBug({Key key}) : super(key: key);
- @override
- _ListViewBugState createState() => _ListViewBugState();
- }
- class _ListViewBugState extends State<ListViewBug> {
- List<String> _originalProductList = [
- "Product 1",
- "Product 2",
- "Product 3",
- ];
- List<String> _productList;
- @override
- initState() {
- super.initState();
- _productList = _originalProductList;
- _filtered = false;
- }
- bool _filtered;
- toggleFilter() {
- setState(() {
- _filtered = !_filtered;
- if (_filtered) {
- _productList = _originalProductList.getRange(1, 3).toList();
- } else {
- _productList = _originalProductList;
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return Wrap(
- children: <Widget>[
- FlatButton(
- child: Text("Toggle filter"), onPressed: () => toggleFilter()),
- Container(
- child: ListView(
- shrinkWrap: true,
- children: _productList
- .map(
- (item) => Chip(
- key: Key(item),
- label: Text(
- item,
- ),
- ),
- )
- .toList(),
- ),
- ),
- ],
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement