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

outdated

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, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  final 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) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: [
          IconButton(
            icon: Icon(Icons.add),
            onPressed: () {
              _controller.insertItem(_num, _num);
              _num++;
            },
          ),
          IconButton(
            icon: Icon(Icons.remove),
            onPressed: () {
              _num--;
              _controller.removeItem(_num);
            },
          ),
        ],
      ),
      body: CustomScrollView(
        slivers: [
          ExpandableSliverList<int>(
            initialItems: _nums,
            controller: _controller,
            // startCollapsed: true,
            duration: const Duration(milliseconds: 500),
            builder: (context, item) {
              return ListTile(
                title: Text(item.toString()),
              );
            },
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _toggleList,
        child: Icon(Icons.add),
      ),
    );
  }
}
27
likes
0
pub points
80%
popularity

Publisher

verified publishertylernorbury.com

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

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on expandable_sliver_list