Show error and stacktrace if need on initial sync

Closes #124.
parent acd83ad8
......@@ -12,7 +12,18 @@ export 'state.dart';
class StartBloc extends Bloc<StartEvent, StartState> {
final Matrix _matrix;
StreamSubscription _errorSub;
StartBloc(this._matrix) {
_matrix.userAvaible.then(
(_) => _errorSub = _matrix.user.updates.listen(
(_) {},
onError: ((error, stackTrace) {
add(_NotifyError(error, stackTrace));
}),
),
);
_matrix.firstSync.then((_) => add(_NotifyLoadingDone()));
}
......@@ -30,7 +41,24 @@ class StartBloc extends Bloc<StartEvent, StartState> {
if (event is _NotifyLoadingDone) {
yield Finished();
}
if (event is _NotifyError) {
yield ErrorOccurred(event.error, event.stackTrace);
}
}
@override
Future<void> close() async {
await _errorSub.cancel();
await super.close();
}
}
class _NotifyLoadingDone extends StartEvent {}
class _NotifyError extends StartEvent {
final dynamic error;
final StackTrace stackTrace;
_NotifyError(this.error, this.stackTrace);
}
......@@ -72,6 +72,14 @@ class _StartPageState extends State<StartPage> {
}
},
builder: (context, state) {
if (state is ErrorOccurred) {
// TODO: Handle differently in 1.0
return _ErrorPage(
error: state.error,
stackTrace: state.stackTrace,
);
}
return Stack(
children: <Widget>[
if (_logoVisible)
......@@ -178,3 +186,89 @@ class _LoadingPage extends StatelessWidget {
);
}
}
class _ErrorPage extends StatelessWidget {
final dynamic error;
final StackTrace stackTrace;
const _ErrorPage({
Key key,
@required this.error,
this.stackTrace,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 32,
vertical: 64,
),
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: <Widget>[
Icon(
Icons.bug_report,
size: 32,
color: Theme.of(context).textTheme.caption.color,
),
SizedBox(width: 16),
Expanded(
child: RichText(
text: TextSpan(
style: DefaultTextStyle.of(context).style.copyWith(
fontSize: 16,
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text:
'${context.intl.error.anErrorHasOccurred}\n',
),
TextSpan(
text: error.toString(),
style: TextStyle(
fontFamily: 'monospace',
fontWeight: FontWeight.normal,
),
),
],
),
),
),
],
),
),
if (stackTrace != null && stackTrace != StackTrace.empty)
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Scrollbar(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(16).copyWith(top: 0),
child: Text(
stackTrace.toString(),
style: TextStyle(
fontFamily: 'monospace',
),
),
),
),
),
),
),
],
),
),
),
);
}
}
......@@ -16,4 +16,11 @@ class StartState extends Equatable {
List<Object> get props => [currentStep];
}
class ErrorOccurred extends StartState {
final dynamic error;
final StackTrace stackTrace;
ErrorOccurred(this.error, this.stackTrace);
}
class Finished extends StartState {}
......@@ -309,8 +309,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "397752c584d3f62f796aa61b80519c86167a0cba"
resolved-ref: "397752c584d3f62f796aa61b80519c86167a0cba"
ref: "0318f6487c547061ee29ef8cfe56dd1e8494f98f"
resolved-ref: "0318f6487c547061ee29ef8cfe56dd1e8494f98f"
url: "https://git.pattle.im/pattle/library/matrix-dart-sdk.git"
source: git
version: "0.0.0"
......
......@@ -13,7 +13,7 @@ dependencies:
matrix_sdk:
git:
url: https://git.pattle.im/pattle/library/matrix-dart-sdk.git
ref: 397752c584d3f62f796aa61b80519c86167a0cba
ref: 0318f6487c547061ee29ef8cfe56dd1e8494f98f
async: ^2.3.0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment