From c63692ec31b08aea0eeb1b77237a689c2e63efcf Mon Sep 17 00:00:00 2001 From: Nutcake Date: Tue, 2 May 2023 10:22:04 +0200 Subject: [PATCH] Improve chat-view error visuals --- lib/api_client.dart | 8 ++++++++ lib/widgets/messages.dart | 30 +++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/api_client.dart b/lib/api_client.dart index ac128e8..0f91efb 100644 --- a/lib/api_client.dart +++ b/lib/api_client.dart @@ -88,6 +88,14 @@ class ApiClient { } static void checkResponse(http.Response response) { + if (response.statusCode == 429) { + throw "Sorry, you are being rate limited"; + } + if (response.statusCode == 403) { + tryCachedLogin(); + // TODO: Show the login screen again if cached login was unsuccessful. + throw "You are not authorized to do that."; + } if (response.statusCode != 200) { throw "Unknown Error${kDebugMode ? ": ${response.statusCode}|${response.body}" : ""}"; } diff --git a/lib/widgets/messages.dart b/lib/widgets/messages.dart index e7ed197..b676d36 100644 --- a/lib/widgets/messages.dart +++ b/lib/widgets/messages.dart @@ -92,6 +92,24 @@ class _MessagesState extends State { builder: (context, snapshot) { if (snapshot.hasData) { final cache = snapshot.data as MessageCache; + if (cache.messages.isEmpty) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.message_outlined), + Padding( + padding: const EdgeInsets.symmetric(vertical: 24), + child: Text( + "There are no messages here\nWhy not say hello?", + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleMedium, + ), + ) + ], + ), + ); + } return ListView.builder( reverse: true, itemCount: cache.messages.length, @@ -115,9 +133,10 @@ class _MessagesState extends State { .of(context) .textTheme .titleMedium,), - const SizedBox(height: 16,), - Text("${snapshot.error}"), - const Spacer(), + Padding( + padding: const EdgeInsets.all(16), + child: Text("${snapshot.error}"), + ), TextButton.icon( onPressed: () { setState(() { @@ -125,10 +144,7 @@ class _MessagesState extends State { }); }, style: TextButton.styleFrom( - backgroundColor: Theme - .of(context) - .colorScheme - .secondaryContainer, + padding: const EdgeInsets.symmetric( vertical: 16, horizontal: 16), ),