fix user list error handling

This commit is contained in:
Salvatore Giordano
2021-06-28 13:08:51 +02:00
parent 07f3a8be87
commit a3a88aead1
2 changed files with 8 additions and 9 deletions
@@ -128,7 +128,7 @@ class UserListView extends StatefulWidget {
final int crossAxisCount;
/// The builder that will be used in case of error
final Widget Function(Error error)? errorBuilder;
final ErrorBuilder? errorBuilder;
/// The builder that will be used to build the list
final Widget Function(BuildContext context, List<ListItem> users)?
@@ -153,8 +153,8 @@ class _UserListViewState extends State<UserListView>
@override
Widget build(BuildContext context) {
final child = UserListCore(
errorBuilder: widget.errorBuilder as Widget Function(Object)? ??
(err) => _buildError(err as Error),
errorBuilder: widget.errorBuilder ??
(BuildContext context, Object err) => _buildError(err),
emptyBuilder: widget.emptyBuilder ?? (context) => _buildEmpty(),
loadingBuilder: widget.loadingBuilder ??
(context) => LayoutBuilder(
@@ -194,12 +194,10 @@ class _UserListViewState extends State<UserListView>
bool get isListAlreadySorted =>
widget.sort?.any((e) => e.field == 'name' && e.direction == 1) ?? false;
Widget _buildError(Error error) {
print(error.stackTrace);
Widget _buildError(Object error) {
var message = error.toString();
if (error is DioError) {
final dioError = error as DioError;
final dioError = error;
if (dioError.type == DioErrorType.response) {
message = dioError.message;
} else {
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter_core/src/users_bloc.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
///
/// [UserListCore] is a simplified class that allows fetching users while
@@ -76,7 +77,7 @@ class UserListCore extends StatefulWidget {
final UserListController? userListController;
/// The builder that will be used in case of error
final Widget Function(Object error) errorBuilder;
final ErrorBuilder errorBuilder;
/// The builder that will be used to build the list
final Widget Function(BuildContext context, List<ListItem> users) listBuilder;
@@ -170,7 +171,7 @@ class UserListCoreState extends State<UserListCore>
stream: _buildUserStream(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return widget.errorBuilder(snapshot.error!);
return widget.errorBuilder(context, snapshot.error!);
}
if (!snapshot.hasData) {
return widget.loadingBuilder(context);