Merge pull request #244 from GetStream/nash/error-builder

[Core] Use standard callback for ErrorBuilder
This commit is contained in:
Salvatore Giordano
2021-01-29 15:38:24 +01:00
committed by GitHub
7 changed files with 19 additions and 17 deletions
@@ -167,7 +167,7 @@ class _ChannelListViewState extends State<ChannelListView>
emptyBuilder: (BuildContext context) {
return _buildEmptyWidget();
},
errorBuilder: (Error error) {
errorBuilder: (BuildContext context, dynamic error) {
return _buildErrorWidget(context);
},
loadingBuilder: (BuildContext context) {
@@ -148,7 +148,7 @@ class _MessageSearchListViewState extends State<MessageSearchListView> {
},
);
},
errorBuilder: (error) {
errorBuilder: (BuildContext context, dynamic error) {
if (error is Error) {
print((error).stackTrace);
}
@@ -159,9 +159,8 @@ class _MessageSearchListViewState extends State<MessageSearchListView> {
var message = error.toString();
if (error is DioError) {
final dioError = error as DioError;
if (dioError.type == DioErrorType.RESPONSE) {
message = dioError.message;
if (error.type == DioErrorType.RESPONSE) {
message = error.message;
} else {
message = 'Check your connection and retry';
}
@@ -89,7 +89,7 @@ class HomeScreen extends StatelessWidget {
),
);
},
errorBuilder: (Error error) {
errorBuilder: (BuildContext context, dynamic error) {
return Center(
child: Text(
'Oh no, something went wrong. Please check your config.'),
@@ -5,6 +5,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/channels_bloc.dart';
import 'package:stream_chat_flutter_core/src/typedef.dart';
import 'stream_chat_core.dart';
@@ -72,7 +73,7 @@ class ChannelListCore extends StatefulWidget {
final ChannelListController channelListController;
/// 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 in case of loading
final WidgetBuilder loadingBuilder;
@@ -162,7 +163,7 @@ class _ChannelListCoreState extends State<ChannelListCore>
print((snapshot.error as Error).stackTrace);
}
return widget.errorBuilder(snapshot.error);
return widget.errorBuilder(context, snapshot.error);
}
void loadData() {
@@ -3,14 +3,9 @@ import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter_core/src/typedef.dart';
import 'stream_channel.dart';
/// A signature for a callback which exposes an error and returns a function.
/// This Callback can be used in cases where an API failure occurs and the widget
/// is unable to render data.
typedef StreamErrorBuilder = Widget Function(
BuildContext context, Object error);
/// [MessageListCore] is a simplified class that allows fetching a list of messages while exposing UI builders.
/// A [MessageListController] is used to paginate data.
///
@@ -89,7 +84,7 @@ class MessageListCore extends StatefulWidget {
/// Callback triggered when an error occurs while performing the given request.
/// This parameter can be used to display an error message to users in the event
/// of a connection failure.
final StreamErrorBuilder errorWidgetBuilder;
final ErrorBuilder errorWidgetBuilder;
/// If true will show a scroll to bottom message when there are new messages and the scroll offset is not zero
final bool showScrollToBottom;
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter_core/src/typedef.dart';
import 'message_search_bloc.dart';
///
@@ -82,7 +83,7 @@ class MessageSearchListCore extends StatefulWidget {
final WidgetBuilder emptyBuilder;
/// 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 in case of loading
final WidgetBuilder loadingBuilder;
@@ -125,7 +126,7 @@ class _MessageSearchListCoreState extends State<MessageSearchListCore> {
print((snapshot.error as Error).stackTrace);
}
return widget.errorBuilder(snapshot.error);
return widget.errorBuilder(context, snapshot.error);
}
if (!snapshot.hasData) {
@@ -0,0 +1,6 @@
import 'package:flutter/widgets.dart';
/// A signature for a callback which exposes an error and returns a function.
/// This Callback can be used in cases where an API failure occurs and the widget
/// is unable to render data.
typedef ErrorBuilder = Widget Function(BuildContext context, Object error);