expandable_sliver_list 4.1.1 copy "expandable_sliver_list: ^4.1.1" to clipboard
expandable_sliver_list: ^4.1.1 copied to clipboard

A sliver List that you can then either expand or collapse, in order to show or hide the contents of the list.

example/lib/main.dart

import 'package:expandable_sliver_list/expandable_sliver_list.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Expandable Sliver List Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Expandable Sliver List Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<int> _nums = [0];

  int _num = 1;

  ExpandableSliverListController<int> _controller =
      ExpandableSliverListController<int>();

  void _toggleList() {
    if (_controller.isCollapsed()) {
      _controller.expand();
    } else {
      _controller.collapse();
    }
  }

  @override
  Widget build(BuildContext context) {
    _controller.setItems(_nums);

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: [
          IconButton(
            icon: Icon(Icons.add),
            onPressed: () {
              setState(() {
                _controller.insertItem(_num, _num);
                _nums.insert(_num, _num);

                _num++;
              });
            },
          ),
          IconButton(
            icon: Icon(Icons.remove),
            onPressed: () {
              setState(() {
                _num--;

                _nums.removeAt(_num);
                _controller.removeItem(_num);
              });
            },
          ),
          IconButton(
            icon: Icon(Icons.refresh),
            onPressed: () {
              setState(() {
                _nums = [0, 1, 2, 3];
                _num = 4;
              });
            },
          )
        ],
      ),
      body: CustomScrollView(
        slivers: [
          ExpandableSliverList<int>(
            initialItems: _nums,
            controller: _controller,
            duration: const Duration(milliseconds: 500),
            builder: (context, item, index) {
              return ListTile(
                title: Text(item.toString()),
              );
            },
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _toggleList,
        child: Icon(Icons.add),
      ),
    );
  }
}
28
likes
150
points
990
downloads

Publisher

verified publishertylernorbury.com

Weekly Downloads

A sliver List that you can then either expand or collapse, in order to show or hide the contents of the list.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on expandable_sliver_list