Skip to content
This repository was archived by the owner on Sep 14, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/assets/bad_connection.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions app/lib/bad_connection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class BadConnection extends StatelessWidget {
const BadConnection();

@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset(
'assets/bad_connection.svg',
height: 300.0,
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Bad Connection: Unable to reach the avary'),
),
],
),
);
}
}
6 changes: 3 additions & 3 deletions app/lib/posts_list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'bad_connection.dart';
import 'models/post.dart';
import 'no_content.dart';
import 'post_item.dart';
Expand All @@ -15,12 +15,12 @@ class PostsList extends StatelessWidget {
stream: posts,
builder: (BuildContext context, AsyncSnapshot<List<Post>> snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
return const BadConnection();
}

switch (snapshot.connectionState) {
case ConnectionState.waiting:
return const Text('Loading...');
return const CircularProgressIndicator();
default:
if (snapshot.data.isEmpty) {
return const NoContent();
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ flutter:
assets:
- assets/undraw_a_day_at_the_park_owg1.svg
- assets/google_g_logo.png
- assets/bad_connection.svg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
Expand Down
17 changes: 17 additions & 0 deletions app/test/bad_connection_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:birb/bad_connection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('Renders content', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MaterialApp(
home: BadConnection(),
));

expect(find.byType(SvgPicture), findsOneWidget);
expect(
find.text('Bad Connection: Unable to reach the avary'), findsOneWidget);
});
}
7 changes: 4 additions & 3 deletions app/test/posts_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
home: PostsList(mockPosts(count: 5)),
));

expect(find.text('Loading...'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsOneWidget);

await tester.pump(Duration.zero);

Expand All @@ -34,14 +34,15 @@ void main() {
expect(find.byType(NoContent), findsOneWidget);
});

testWidgets('renders NoContent widget', (WidgetTester tester) async {
testWidgets('renders BadConnection widget', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MaterialApp(
home: PostsList(Future<List<Post>>.error('Bad Connection').asStream()),
));
await tester.pump(Duration.zero);

expect(find.text('Error: Bad Connection'), findsOneWidget);
expect(find.text('Bad Connection: Unable to reach the avary'),
findsOneWidget);
});
});
}