123 lines
3.9 KiB
Dart
123 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../l10n/app_localizations.dart';
|
|
import '../../pages/auth/auth_view.dart';
|
|
import '../data/services/auth_controller.dart';
|
|
import '../theme/app_colors.dart';
|
|
|
|
/// 打开登录 / 注册页(沿用现有 Navigator 风格,不引路由库)
|
|
Future<void> openAuthPage(BuildContext context, {bool signUpMode = false}) {
|
|
return Navigator.of(context).push(
|
|
MaterialPageRoute<void>(builder: (_) => AuthPage(signUpMode: signUpMode)),
|
|
);
|
|
}
|
|
|
|
/// 受限动作的登录闸:已登录返回 true;未登录弹底部提示并引导登录,返回 false。
|
|
///
|
|
/// 首页/发现/详情保持匿名可看,只有收藏、点赞、评论这类"要对到具体账号"的动作才走这里。
|
|
Future<bool> ensureSignedIn(BuildContext context) async {
|
|
final auth = context.read<AuthController>();
|
|
if (auth.isSignedIn) return true;
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final go = await showModalBottomSheet<bool>(
|
|
context: context,
|
|
backgroundColor: AppColors.card,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(18)),
|
|
),
|
|
builder: (sheetContext) => SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
l10n.authGateTitle,
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
l10n.authGateMessage,
|
|
style: const TextStyle(color: AppColors.muted, fontSize: 13),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: () => Navigator.of(sheetContext).pop(false),
|
|
child: Text(l10n.cancel),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: FilledButton(
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: AppColors.blue,
|
|
),
|
|
onPressed: () => Navigator.of(sheetContext).pop(true),
|
|
child: Text(l10n.authGateAction),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
if (go == true && context.mounted) {
|
|
await openAuthPage(context);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// 页面级登录引导,用于记录、收藏和下载等必须登录的独立页面。
|
|
class AuthGatePanel extends StatelessWidget {
|
|
const AuthGatePanel({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
return Center(
|
|
key: const Key('auth-gate-panel'),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
l10n.authGateTitle,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
l10n.authGateMessage,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(color: AppColors.muted, fontSize: 13),
|
|
),
|
|
const SizedBox(height: 18),
|
|
FilledButton(
|
|
onPressed: () => openAuthPage(context),
|
|
child: Text(l10n.authGateAction),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|