Skip to content

Commit

Permalink
feat: nndb migration (#6) (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Apr 5, 2021
1 parent 6a27fc3 commit 4b271be
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 110 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _CustomInfiniteList extends StatelessWidget {
},
),
onError: (context, retry, error) {
Scaffold.of(context)
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(error.toString()),
Expand All @@ -119,7 +119,7 @@ class _CustomInfiniteList extends StatelessWidget {
}
}

Future<List<String>> _itemLoader(int limit, {int start = 0}) async {
Future<List<String>?> _itemLoader(int limit, {int start = 0}) async {
await Future<void>.delayed(const Duration(seconds: 1));
if (start >= 100) return null;
if (Random().nextInt(2) == 0) throw Exception('Oops!');
Expand All @@ -136,9 +136,9 @@ class _Loading extends StatelessWidget {

class _Error extends StatelessWidget {
const _Error({
Key key,
this.error,
this.retry,
Key? key,
required this.error,
required this.retry,
}) : super(key: key);

final Object error;
Expand All @@ -153,7 +153,7 @@ class _Error extends StatelessWidget {
children: [
Text(
error.toString(),
style: theme.textTheme.headline4.copyWith(color: theme.errorColor),
style: theme.textTheme.headline4?.copyWith(color: theme.errorColor),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Expand All @@ -169,7 +169,7 @@ class _Error extends StatelessWidget {
}

class _ErrorLoader extends StatelessWidget {
const _ErrorLoader({Key key, @required this.retry}) : super(key: key);
const _ErrorLoader({Key? key, required this.retry}) : super(key: key);
final VoidCallback retry;

@override
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish_to: none
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand All @@ -14,7 +14,7 @@ dependencies:
path: ../

dev_dependencies:
very_good_analysis: ^1.0.4
very_good_analysis: ^2.0.0

flutter:
uses-material-design: true
82 changes: 40 additions & 42 deletions lib/very_good_infinite_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InfiniteListException implements Exception {}
///
/// * [limit] is the number of items you'd like to fetch.
/// * [start] is an optional offset which defaults to 0.
typedef ItemLoader<T> = Future<List<T>> Function(int limit, {int start});
typedef ItemLoader<T> = Future<List<T>?> Function(int limit, {int start});

/// Function which returns a [Widget] given a [context], [retry], and [error].
/// Used by [InfiniteList] to render widgets in response to exceptions thrown
Expand Down Expand Up @@ -48,15 +48,15 @@ typedef OnError = void Function(
class InfiniteListBuilder<T> {
/// {@macro infinite_list_builder}
const InfiniteListBuilder({
@required this.success,
WidgetBuilder loading,
ErrorBuilder error,
WidgetBuilder empty,
required this.success,
WidgetBuilder? loading,
ErrorBuilder? error,
WidgetBuilder? empty,
}) : _loading = loading,
_error = error,
_empty = empty;

final WidgetBuilder _loading;
final WidgetBuilder? _loading;

/// [WidgetBuilder] which is invoked when the [InfiniteList]
/// is rendered while content is being fetched by the [ItemLoader].
Expand All @@ -73,7 +73,7 @@ class InfiniteListBuilder<T> {
/// retrieved from the [ItemLoader].
final Widget Function(BuildContext, T) success;

final ErrorBuilder _error;
final ErrorBuilder? _error;

/// [WidgetBuilder] which is invoked when the [InfiniteList]
/// is rendered and an [InfiniteListException]
Expand All @@ -89,7 +89,7 @@ class InfiniteListBuilder<T> {
};
}

final WidgetBuilder _empty;
final WidgetBuilder? _empty;

/// [WidgetBuilder] which is invoked when the [InfiniteList]
/// is rendered and the [ItemLoader] has returned an empty list.
Expand All @@ -109,28 +109,26 @@ class InfiniteListBuilder<T> {
class InfiniteList<T> extends StatefulWidget {
/// {@macro infinite_list}
const InfiniteList({
Key key,
@required this.itemLoader,
@required this.builder,
WidgetBuilder bottomLoader,
ErrorBuilder errorLoader,
Key? key,
required this.itemLoader,
required this.builder,
WidgetBuilder? bottomLoader,
ErrorBuilder? errorLoader,
ScrollController? scrollController,
this.debounceDuration,
this.reverse = false,
this.onError,
this.padding,
ScrollController scrollController,
double scrollOffsetThreshold,
}) : assert(itemLoader != null),
assert(builder != null),
_bottomLoader = bottomLoader,
double? scrollOffsetThreshold,
}) : _bottomLoader = bottomLoader,
_errorLoader = errorLoader,
_scrollController = scrollController,
_scrollOffsetThreshold =
scrollOffsetThreshold ?? _kScrollOffsetThreshold,
super(key: key);

/// The amount of space by which to inset the children of the [builder].
final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry? padding;

/// {@macro infinite_list_builder}
final InfiniteListBuilder<T> builder;
Expand All @@ -139,7 +137,7 @@ class InfiniteList<T> extends StatefulWidget {
/// to lazily fetch content.
final ItemLoader<T> itemLoader;

final WidgetBuilder _bottomLoader;
final WidgetBuilder? _bottomLoader;

/// [WidgetBuilder] which is responsible for rendering the bottom loader
/// widget which is rendered when the user scrolls to the bottom of the list
Expand All @@ -152,7 +150,7 @@ class InfiniteList<T> extends StatefulWidget {
);
}

final ErrorBuilder _errorLoader;
final ErrorBuilder? _errorLoader;

/// [WidgetBuilder] which is responsible for rendering the bottom loader
/// widget which is rendered when additional content is unable to be loaded
Expand All @@ -167,13 +165,13 @@ class InfiniteList<T> extends StatefulWidget {
);

/// {@macro on_error}
final OnError onError;
final OnError? onError;

final ScrollController _scrollController;
final ScrollController? _scrollController;

/// Debounce duration for the [itemLoader].
/// Defaults to `const Duration(milliseconds: 100)`.
final Duration debounceDuration;
final Duration? debounceDuration;

/// Whether the scroll view scrolls in the reading direction.
///
Expand All @@ -196,9 +194,9 @@ class InfiniteList<T> extends StatefulWidget {
}

class _InfiniteListState<T> extends State<InfiniteList<T>> {
ScrollController _scrollController;
_ListController<T> _controller;
_Debouncer _debouncer;
late ScrollController _scrollController;
late _ListController<T> _controller;
late _Debouncer _debouncer;

void _onListStateChanged() {
final state = _controller.value;
Expand All @@ -225,7 +223,7 @@ class _InfiniteListState<T> extends State<InfiniteList<T>> {

@override
void dispose() {
_debouncer?.dispose();
_debouncer.dispose();
_controller
..removeListener(_onListStateChanged)
..dispose();
Expand All @@ -250,7 +248,7 @@ class _InfiniteListState<T> extends State<InfiniteList<T>> {
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: _controller,
builder: (context, state, child) {
builder: (context, _ListState<T> state, child) {
final itemCount = state.hasReachedMax == false
? state.items.length + 1
: state.items.length;
Expand Down Expand Up @@ -314,9 +312,9 @@ class _InfiniteListState<T> extends State<InfiniteList<T>> {

class _DefaultError extends StatelessWidget {
const _DefaultError({
Key key,
this.error,
this.retry,
Key? key,
required this.error,
required this.retry,
}) : super(key: key);

final Object error;
Expand All @@ -331,7 +329,7 @@ class _DefaultError extends StatelessWidget {
children: [
Text(
'$error',
style: theme.textTheme.headline4.copyWith(color: theme.errorColor),
style: theme.textTheme.headline4?.copyWith(color: theme.errorColor),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Expand All @@ -346,7 +344,7 @@ class _DefaultError extends StatelessWidget {
}

class _DefaultErrorLoader extends StatelessWidget {
const _DefaultErrorLoader({Key key, @required this.retry}) : super(key: key);
const _DefaultErrorLoader({Key? key, required this.retry}) : super(key: key);
final VoidCallback retry;

@override
Expand All @@ -368,7 +366,7 @@ class _ListException implements Exception {

final Object value;

static const none = _ListException(null);
static const none = _ListException(Object());
}

class _ListState<T> {
Expand All @@ -387,11 +385,11 @@ class _ListState<T> {
final _ListException exception;

_ListState<T> copyWith({
@required _ListStatus status,
int currentIndex,
List<T> items,
bool hasReachedMax,
_ListException exception,
required _ListStatus status,
int? currentIndex,
List<T>? items,
bool? hasReachedMax,
_ListException? exception,
}) {
return _ListState<T>(
currentIndex: currentIndex ?? this.currentIndex,
Expand Down Expand Up @@ -455,10 +453,10 @@ class _ListController<T> extends ValueNotifier<_ListState<T>> {
}

class _Debouncer {
_Debouncer({Duration delay}) : _delay = delay ?? _kDebounceDuration;
_Debouncer({Duration? delay}) : _delay = delay ?? _kDebounceDuration;

final Duration _delay;
Timer _timer;
Timer? _timer;

void call(void Function() action) {
_timer?.cancel();
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: very_good_infinite_list
description: >-
A Very Good Infinite List Widget created by Very Good Ventures.
Comes in handy when making activity feeds, news feeds, etc.
version: 0.2.1
version: 0.3.0
repository: https://github.com/VeryGoodOpenSource/very_good_infinite_list
issue_tracker: https://github.com/VeryGoodOpenSource/very_good_infinite_list/issues
homepage: https://github.com/VeryGoodOpenSource/very_good_infinite_list
documentation: https://github.com/VeryGoodOpenSource/very_good_infinite_list

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"

dependencies:
flutter:
Expand All @@ -19,4 +19,4 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
very_good_analysis: ^1.0.4
very_good_analysis: ^2.0.0
Loading

0 comments on commit 4b271be

Please sign in to comment.