Sign in check

This commit is contained in:
LittleSheep 2024-04-19 18:02:53 +08:00
parent fa7b18fa98
commit 82fc191bad
4 changed files with 76 additions and 23 deletions

View File

@ -5,6 +5,7 @@
"account": "Account", "account": "Account",
"signIn": "Sign In", "signIn": "Sign In",
"signInCaption": "Sign in to create post, start a realm, message your friend and more!", "signInCaption": "Sign in to create post, start a realm, message your friend and more!",
"signInRequired": "Sign in required",
"signUp": "Sign Up", "signUp": "Sign Up",
"signUpCaption": "Create an account on Solarpass and then get the access of entire Solar Networks!", "signUpCaption": "Create an account on Solarpass and then get the access of entire Solar Networks!",
"confirmation": "Confirmation", "confirmation": "Confirmation",

View File

@ -5,6 +5,7 @@
"account": "账号", "account": "账号",
"signIn": "登陆", "signIn": "登陆",
"signInCaption": "登陆以发表帖子、文章、创建领域、和你的朋友聊天,以及获取更多功能!", "signInCaption": "登陆以发表帖子、文章、创建领域、和你的朋友聊天,以及获取更多功能!",
"signInRequired": "请先登陆",
"signUp": "注册", "signUp": "注册",
"signUpCaption": "在 Solarpass 注册一个账号以获得整个 Solar Networks 的存取权!", "signUpCaption": "在 Solarpass 注册一个账号以获得整个 Solar Networks 的存取权!",
"confirmation": "确认", "confirmation": "确认",

View File

@ -8,6 +8,7 @@ import 'package:solian/router.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';
import 'package:solian/widgets/indent_wrapper.dart'; import 'package:solian/widgets/indent_wrapper.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:solian/widgets/signin_required.dart';
class ChatIndexScreen extends StatefulWidget { class ChatIndexScreen extends StatefulWidget {
const ChatIndexScreen({super.key}); const ChatIndexScreen({super.key});
@ -50,33 +51,43 @@ class _ChatIndexScreenState extends State<ChatIndexScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final auth = context.read<AuthProvider>();
return IndentWrapper( return IndentWrapper(
title: AppLocalizations.of(context)!.chat, title: AppLocalizations.of(context)!.chat,
child: RefreshIndicator( child: FutureBuilder(
onRefresh: () => fetchChannels(context), future: auth.isAuthorized(),
child: ListView.builder( builder: (context, snapshot) {
itemCount: _channels.length, if (!snapshot.hasData || !snapshot.data!) {
itemBuilder: (context, index) { return const SignInRequiredScreen();
final element = _channels[index]; }
return ListTile(
leading: const CircleAvatar( return RefreshIndicator(
backgroundColor: Colors.indigo, onRefresh: () => fetchChannels(context),
child: Icon(Icons.tag, color: Colors.white), 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,
},
);
},
); );
}, }),
),
),
); );
} }
} }

View File

@ -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');
},
);
}
}