Deprecate diff utils, MoorAnimatedList

This commit is contained in:
Simon Binder 2019-07-28 14:45:36 +02:00
parent 7f79fd922b
commit 7a9cafb02f
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 22 additions and 33 deletions

View File

@ -1,6 +1,7 @@
/// A utility library to find an edit script that turns a list into another.
/// This is useful when displaying a updating stream of immutable lists in a
/// list that can be updated.
@Deprecated('Will be removed in moor 2.0')
library diff_util;
import 'package:moor/src/utils/android_diffutils_port.dart' as impl;

View File

@ -47,6 +47,7 @@ class DiffInput<T> {
}
}
@Deprecated('Will be removed in moor 2.0')
List<Snake> calculateDiff(DiffInput input) {
final oldSize = input.from.length;
final newSize = input.to.length;

View File

@ -5,7 +5,6 @@ import 'package:moor_example/database/database.dart';
import 'package:moor_example/main.dart';
import 'package:moor_example/widgets/categories_drawer.dart';
import 'package:moor_example/widgets/todo_card.dart';
import 'package:moor_flutter/moor_flutter.dart';
// ignore_for_file: prefer_const_constructors
@ -32,39 +31,23 @@ class HomeScreenState extends State<HomeScreen> {
drawer: CategoriesDrawer(),
// A moorAnimatedList automatically animates incoming and leaving items, we only
// have to tell it what data to display and how to turn data into widgets.
body: MoorAnimatedList<EntryWithCategory>(
// we want to show an updating stream of all relevant entries
body: StreamBuilder<List<EntryWithCategory>>(
stream: bloc.homeScreenEntries,
// consider items equal if their id matches. Otherwise, we'd get an
// animation of an old item leaving and another one coming in every time
// the content of an item changed!
equals: (a, b) => a.entry.id == b.entry.id,
itemBuilder: (ctx, item, animation) {
// When a new item arrives, it will expand vertically
return SizeTransition(
key: ObjectKey(item.entry.id),
sizeFactor: animation,
axis: Axis.vertical,
child: TodoCard(item.entry),
);
},
removedItemBuilder: (ctx, item, animation) {
// and it will leave the same way after being deleted.
return SizeTransition(
key: ObjectKey(item.entry.id),
sizeFactor: animation,
axis: Axis.vertical,
child: AnimatedBuilder(
animation:
CurvedAnimation(parent: animation, curve: Curves.easeOut),
child: TodoCard(item.entry),
builder: (context, child) {
return Opacity(
opacity: animation.value,
child: child,
);
},
),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const Align(
alignment: Alignment.center,
child: CircularProgressIndicator(),
);
}
final activeTodos = snapshot.data;
return ListView.builder(
itemCount: activeTodos.length,
itemBuilder: (context, index) {
return TodoCard(activeTodos[index].entry);
},
);
},
),

View File

@ -1,6 +1,8 @@
import 'dart:async';
import 'package:flutter/widgets.dart';
// ignore: deprecated_member_use
import 'package:moor/diff_util.dart';
typedef Widget ItemBuilder<T>(
@ -9,6 +11,8 @@ typedef Widget RemovedItemBuilder<T>(
BuildContext context, T item, Animation<double> anim);
/// An [AnimatedList] that shows the result of a moor query stream.
@Deprecated('Will be removed in moor 2.0. You could use the '
'animated_stream_list package as an alternative')
class MoorAnimatedList<T> extends StatefulWidget {
final Stream<List<T>> stream;
final ItemBuilder<T> itemBuilder;