From ee6f80041925459eb6dfb53bcc29a9bf71dec51f Mon Sep 17 00:00:00 2001 From: Gerard Horgan Date: Sun, 16 Dec 2018 15:23:44 +0000 Subject: [PATCH 1/3] added progressionIndicator and corrsponding test --- app/lib/posts_list.dart | 2 +- app/test/posts_list_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/posts_list.dart b/app/lib/posts_list.dart index 9730c6d..cadf60b 100644 --- a/app/lib/posts_list.dart +++ b/app/lib/posts_list.dart @@ -20,7 +20,7 @@ class PostsList extends StatelessWidget { switch (snapshot.connectionState) { case ConnectionState.waiting: - return const Text('Loading...'); + return const CircularProgressIndicator(); default: if (snapshot.data.isEmpty) { return const NoContent(); diff --git a/app/test/posts_list_test.dart b/app/test/posts_list_test.dart index b4d4b3b..d6c9e1d 100644 --- a/app/test/posts_list_test.dart +++ b/app/test/posts_list_test.dart @@ -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); From 4fcd09cab41fcf1fd93f9d26e8d2092ba6e65517 Mon Sep 17 00:00:00 2001 From: Gerard Horgan Date: Sun, 16 Dec 2018 16:22:52 +0000 Subject: [PATCH 2/3] adding error loading svg --- app/assets/bad_connection.svg | 40 +++++++++++++++++++++++++++++++ app/lib/bad_connection.dart | 0 app/test/bad_connection_test.dart | 0 3 files changed, 40 insertions(+) create mode 100644 app/assets/bad_connection.svg create mode 100644 app/lib/bad_connection.dart create mode 100644 app/test/bad_connection_test.dart diff --git a/app/assets/bad_connection.svg b/app/assets/bad_connection.svg new file mode 100644 index 0000000..14bd615 --- /dev/null +++ b/app/assets/bad_connection.svg @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/lib/bad_connection.dart b/app/lib/bad_connection.dart new file mode 100644 index 0000000..e69de29 diff --git a/app/test/bad_connection_test.dart b/app/test/bad_connection_test.dart new file mode 100644 index 0000000..e69de29 From 0bf8c4eaf36aeb34d2689f5854f2d2e654f3c98e Mon Sep 17 00:00:00 2001 From: Gerard Horgan Date: Sun, 16 Dec 2018 16:34:59 +0000 Subject: [PATCH 3/3] these files were never commited: I only commited the svg file! in last commit --- app/lib/bad_connection.dart | 26 ++++++++++++++++++++++++++ app/lib/posts_list.dart | 4 ++-- app/pubspec.yaml | 1 + app/test/bad_connection_test.dart | 17 +++++++++++++++++ app/test/posts_list_test.dart | 5 +++-- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/app/lib/bad_connection.dart b/app/lib/bad_connection.dart index e69de29..9d7afe7 100644 --- a/app/lib/bad_connection.dart +++ b/app/lib/bad_connection.dart @@ -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: [ + 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'), + ), + ], + ), + ); + } +} diff --git a/app/lib/posts_list.dart b/app/lib/posts_list.dart index cadf60b..4d7c7b7 100644 --- a/app/lib/posts_list.dart +++ b/app/lib/posts_list.dart @@ -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'; @@ -15,7 +15,7 @@ class PostsList extends StatelessWidget { stream: posts, builder: (BuildContext context, AsyncSnapshot> snapshot) { if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); + return const BadConnection(); } switch (snapshot.connectionState) { diff --git a/app/pubspec.yaml b/app/pubspec.yaml index d08d23c..1dfd62c 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -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. diff --git a/app/test/bad_connection_test.dart b/app/test/bad_connection_test.dart index e69de29..a192261 100644 --- a/app/test/bad_connection_test.dart +++ b/app/test/bad_connection_test.dart @@ -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); + }); +} diff --git a/app/test/posts_list_test.dart b/app/test/posts_list_test.dart index d6c9e1d..500b87b 100644 --- a/app/test/posts_list_test.dart +++ b/app/test/posts_list_test.dart @@ -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>.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); }); }); }