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