diff --git a/lib/i18n/app_en.arb b/lib/i18n/app_en.arb index 8b81cb7..c238c9f 100644 --- a/lib/i18n/app_en.arb +++ b/lib/i18n/app_en.arb @@ -5,6 +5,7 @@ "account": "Account", "signIn": "Sign In", "signInCaption": "Sign in to create post, start a realm, message your friend and more!", + "signInRequired": "Sign in required", "signUp": "Sign Up", "signUpCaption": "Create an account on Solarpass and then get the access of entire Solar Networks!", "confirmation": "Confirmation", diff --git a/lib/i18n/app_zh.arb b/lib/i18n/app_zh.arb index 3e453d6..48cecba 100644 --- a/lib/i18n/app_zh.arb +++ b/lib/i18n/app_zh.arb @@ -5,6 +5,7 @@ "account": "账号", "signIn": "登陆", "signInCaption": "登陆以发表帖子、文章、创建领域、和你的朋友聊天,以及获取更多功能!", + "signInRequired": "请先登陆", "signUp": "注册", "signUpCaption": "在 Solarpass 注册一个账号以获得整个 Solar Networks 的存取权!", "confirmation": "确认", diff --git a/lib/screens/chat/index.dart b/lib/screens/chat/index.dart index 3e575ce..89567ac 100644 --- a/lib/screens/chat/index.dart +++ b/lib/screens/chat/index.dart @@ -8,6 +8,7 @@ import 'package:solian/router.dart'; import 'package:solian/utils/service_url.dart'; import 'package:solian/widgets/indent_wrapper.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:solian/widgets/signin_required.dart'; class ChatIndexScreen extends StatefulWidget { const ChatIndexScreen({super.key}); @@ -50,33 +51,43 @@ class _ChatIndexScreenState extends State { @override Widget build(BuildContext context) { + final auth = context.read(); + return IndentWrapper( title: AppLocalizations.of(context)!.chat, - child: RefreshIndicator( - onRefresh: () => fetchChannels(context), - child: ListView.builder( - itemCount: _channels.length, - itemBuilder: (context, index) { - final element = _channels[index]; - return ListTile( - leading: const CircleAvatar( - backgroundColor: Colors.indigo, - child: Icon(Icons.tag, color: Colors.white), + child: FutureBuilder( + future: auth.isAuthorized(), + builder: (context, snapshot) { + if (!snapshot.hasData || !snapshot.data!) { + return const SignInRequiredScreen(); + } + + return RefreshIndicator( + onRefresh: () => fetchChannels(context), + child: ListView.builder( + itemCount: _channels.length, + itemBuilder: (context, index) { + final element = _channels[index]; + return ListTile( + leading: const CircleAvatar( + backgroundColor: Colors.indigo, + child: Icon(Icons.tag, color: Colors.white), + ), + title: Text(element.name), + subtitle: Text(element.description), + onTap: () { + router.pushNamed( + 'chat.channel', + pathParameters: { + 'channel': element.alias, + }, + ); + }, + ); + }, ), - title: Text(element.name), - subtitle: Text(element.description), - onTap: () { - router.pushNamed( - 'chat.channel', - pathParameters: { - 'channel': element.alias, - }, - ); - }, ); - }, - ), - ), + }), ); } } diff --git a/lib/widgets/signin_required.dart b/lib/widgets/signin_required.dart new file mode 100644 index 0000000..6ab83e0 --- /dev/null +++ b/lib/widgets/signin_required.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:solian/router.dart'; + +class SignInRequiredScreen extends StatelessWidget { + const SignInRequiredScreen({super.key}); + + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Center( + child: Container( + constraints: const BoxConstraints(maxWidth: 340), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.login, size: 40), + const SizedBox(height: 20), + Text( + AppLocalizations.of(context)!.signInRequired, + style: Theme.of(context).textTheme.headlineSmall, + textAlign: TextAlign.center, + ), + const SizedBox(height: 20), + Text( + AppLocalizations.of(context)!.signInCaption, + style: Theme.of(context).textTheme.bodyMedium, + textAlign: TextAlign.center, + ) + ], + ), + ), + ), + onTap: () { + router.goNamed('account'); + }, + ); + } + +} \ No newline at end of file