diffutil_sliverlist 0.2.0+1 copy "diffutil_sliverlist: ^0.2.0+1" to clipboard
diffutil_sliverlist: ^0.2.0+1 copied to clipboard

outdated

A SliverList that implicitly animates changes using diffutil.dart.

example/lib/main.dart

import 'dart:math';

import 'package:diffutil_sliverlist/diffutil_sliverlist.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(const DiffUtilSliverListDemo());

class DiffUtilSliverListDemo extends StatefulWidget {
  const DiffUtilSliverListDemo({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

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

class _DiffUtilSliverListDemoState extends State<DiffUtilSliverListDemo> {
  int _counter = 0;

  List<int> list = [0];

  void _incrementCounter() {
    setState(() {
      _counter++;

      if (Random().nextInt(3) > 0 || list.isEmpty) {
        list = [...list, _counter];
      } else {
        list = [...list];
        list.removeAt(Random().nextInt(list.length));
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text("DiffUtilSliverList Demo"),
        ),
        body: CustomScrollView(
          slivers: [
            DiffUtilSliverList<int>(
              items: list,
              builder: (context, item) => Container(
                color: colors[item % colors.length],
                height: 48,
                width: double.infinity,
              ),
              insertAnimationBuilder: (context, animation, child) =>
                  FadeTransition(
                opacity: animation,
                child: child,
              ),
              removeAnimationBuilder: (context, animation, child) =>
                  SizeTransition(
                sizeFactor: animation,
                child: child,
              ),
              removeAnimationDuration: const Duration(milliseconds: 3000),
              insertAnimationDuration: const Duration(milliseconds: 1200),
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: Icon(Icons.view_list),
        ), // This trailing comma makes auto-formatting nicer for build methods.
      ),
    );
  }

  static const colors = [
    Colors.deepOrangeAccent,
    Colors.blueAccent,
    Colors.greenAccent,
    Colors.yellowAccent
  ];
}
55
likes
0
pub points
83%
popularity

Publisher

verified publisherlittlebat.dev

A SliverList that implicitly animates changes using diffutil.dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

diffutil_dart, flutter

More

Packages that depend on diffutil_sliverlist