Connection state notifier

This commit is contained in:
LittleSheep 2024-06-06 20:23:50 +08:00
parent df7dd85a0c
commit d1a8793550
5 changed files with 64 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import 'package:solian/widgets/chat/call/chat_call_action.dart';
import 'package:solian/widgets/chat/chat_message.dart'; import 'package:solian/widgets/chat/chat_message.dart';
import 'package:solian/widgets/chat/chat_message_action.dart'; import 'package:solian/widgets/chat/chat_message_action.dart';
import 'package:solian/widgets/chat/chat_message_input.dart'; import 'package:solian/widgets/chat/chat_message_input.dart';
import 'package:solian/widgets/current_state_action.dart';
class ChannelChatScreen extends StatefulWidget { class ChannelChatScreen extends StatefulWidget {
final String alias; final String alias;
@ -300,6 +301,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
title: Text(title), title: Text(title),
centerTitle: false, centerTitle: false,
actions: [ actions: [
const BackgroundStateWidget(),
Builder(builder: (context) { Builder(builder: (context) {
if (_isBusy) return const SizedBox(); if (_isBusy) return const SizedBox();
return ChatCallButton( return ChatCallButton(

View File

@ -12,6 +12,7 @@ import 'package:solian/theme.dart';
import 'package:solian/widgets/account/signin_required_overlay.dart'; import 'package:solian/widgets/account/signin_required_overlay.dart';
import 'package:solian/widgets/channel/channel_list.dart'; import 'package:solian/widgets/channel/channel_list.dart';
import 'package:solian/widgets/chat/call/chat_call_indicator.dart'; import 'package:solian/widgets/chat/call/chat_call_indicator.dart';
import 'package:solian/widgets/current_state_action.dart';
class ContactScreen extends StatefulWidget { class ContactScreen extends StatefulWidget {
const ContactScreen({super.key}); const ContactScreen({super.key});
@ -87,6 +88,7 @@ class _ContactScreenState extends State<ContactScreen> {
centerTitle: false, centerTitle: false,
titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24, titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24,
actions: [ actions: [
const BackgroundStateWidget(),
const NotificationButton(), const NotificationButton(),
PopupMenuButton( PopupMenuButton(
icon: const Icon(Icons.add_circle), icon: const Icon(Icons.add_circle),

View File

@ -9,6 +9,7 @@ import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart'; import 'package:solian/screens/account/notification.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/account/signin_required_overlay.dart'; import 'package:solian/widgets/account/signin_required_overlay.dart';
import 'package:solian/widgets/current_state_action.dart';
class RealmListScreen extends StatefulWidget { class RealmListScreen extends StatefulWidget {
const RealmListScreen({super.key}); const RealmListScreen({super.key});
@ -75,6 +76,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
centerTitle: false, centerTitle: false,
titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24, titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24,
actions: [ actions: [
const BackgroundStateWidget(),
const NotificationButton(), const NotificationButton(),
IconButton( IconButton(
icon: const Icon(Icons.add_circle), icon: const Icon(Icons.add_circle),

View File

@ -8,6 +8,7 @@ import 'package:solian/providers/content/post.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart'; import 'package:solian/screens/account/notification.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/posts/post_list.dart'; import 'package:solian/widgets/posts/post_list.dart';
class SocialScreen extends StatefulWidget { class SocialScreen extends StatefulWidget {
@ -82,6 +83,7 @@ class _SocialScreenState extends State<SocialScreen> {
floating: true, floating: true,
titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24, titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24,
actions: [ actions: [
const BackgroundStateWidget(),
const NotificationButton(), const NotificationButton(),
SizedBox( SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16, width: SolianTheme.isLargeScreen(context) ? 8 : 16,

View File

@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:solian/providers/account.dart';
import 'package:solian/providers/chat.dart';
class BackgroundStateWidget extends StatelessWidget {
const BackgroundStateWidget({super.key});
@override
Widget build(BuildContext context) {
final AccountProvider account = Get.find();
final ChatProvider chat = Get.find();
return Obx(() {
final disconnected =
chat.isConnected.isFalse || account.isConnected.isFalse;
final connecting =
chat.isConnecting.isTrue || account.isConnecting.isTrue;
return Row(children: [
if (disconnected && !connecting)
IconButton(
tooltip: [
if (account.isConnected.isFalse)
'Lost Connection with Passport Server...',
if (chat.isConnected.isFalse)
'Lost Connection with Messaging Server...',
].join('\n'),
icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 500.ms)
.then()
.fadeOut(duration: 500.ms),
onPressed: () {
if (account.isConnected.isFalse) account.connect();
if (chat.isConnected.isFalse) chat.connect();
},
),
if (connecting)
IconButton(
tooltip: [
if (account.isConnecting.isTrue)
'Waiting Passport Server Response...',
if (chat.isConnecting.isTrue)
'Waiting Messaging Server Response...',
].join('\n'),
icon: const Icon(Icons.sync)
.animate(onPlay: (c) => c.repeat())
.rotate(duration: 1850.ms, begin: 1, end: 0),
onPressed: () {},
),
]);
});
}
}