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 openAuthPage(BuildContext context, {bool signUpMode = false}) { return Navigator.of(context).push( MaterialPageRoute( builder: (_) => AuthPage(signUpMode: signUpMode), ), ); } /// 受限动作的登录闸:已登录返回 true;未登录弹底部提示并引导登录,返回 false。 /// /// 首页/发现/详情保持匿名可看,只有收藏、点赞、评论这类"要对到具体账号"的动作才走这里。 Future ensureSignedIn(BuildContext context) async { final auth = context.read(); if (auth.isSignedIn) return true; final l10n = AppLocalizations.of(context)!; final go = await showModalBottomSheet( 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: Colors.white, 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; }