fix(genex-mobile): 升级 fluwx 3.x → 5.x,适配新版 API

fluwx 3.x 不含 Android namespace,导致新版 AGP 构建失败。
升级至 5.x 并迁移 API:
- registerWxApi → Fluwx().registerApi()
- weChatResponseEventHandler → fluwx.addSubscriber()
- sendWeChatAuth → fluwx.authBy(NormalAuth)
- isWeChatInstalled → fluwx.isWeChatInstalled
- WXAuthResp → WeChatAuthResponse

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-04 08:42:56 -08:00
parent 7aea49a0c9
commit 2e66db08ef
3 changed files with 14 additions and 11 deletions

View File

@ -28,7 +28,7 @@ import '../../../../core/services/auth_service.dart';
/// flutter build apk --dart-define=WECHAT_APP_ID=wx0000000000000000
///
///
/// : fluwx.sendWeChatAuth WXAuthResp(code) POST /auth/wechat
/// : fluwx.authBy(NormalAuth) WeChatAuthResponse(code) POST /auth/wechat
/// : tobias.aliPayAuth Map(result auth_code) POST /auth/alipay
/// Google: google_sign_in.signIn GoogleSignInAuthentication.idToken POST /auth/google
/// Apple: sign_in_with_apple.getAppleIDCredential identityToken POST /auth/apple
@ -50,13 +50,16 @@ class _WelcomePageState extends State<WelcomePage> {
// 'profile': URL
final _googleSignIn = GoogleSignIn(scopes: ['email', 'profile']);
// fluwx 5.x 使registerApi main.dart
final _fluwx = Fluwx();
@override
void initState() {
super.initState();
// App code
weChatResponseEventHandler.distinct().listen((res) {
if (res is WXAuthResp && mounted) {
_handleWechatAuthResp(res);
_fluwx.addSubscriber((response) {
if (response is WeChatAuthResponse && mounted) {
_handleWechatAuthResp(response);
}
});
}
@ -64,7 +67,7 @@ class _WelcomePageState extends State<WelcomePage> {
//
Future<void> _onWechatTap() async {
final installed = await isWeChatInstalled;
final installed = await _fluwx.isWeChatInstalled;
if (!installed) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
@ -74,13 +77,13 @@ class _WelcomePageState extends State<WelcomePage> {
return;
}
setState(() => _wechatLoading = true);
await sendWeChatAuth(scope: 'snsapi_userinfo', state: 'genex_login');
// weChatResponseEventHandler
await _fluwx.authBy(which: NormalAuth(scope: 'snsapi_userinfo', state: 'genex_login'));
// addSubscriber
}
Future<void> _handleWechatAuthResp(WXAuthResp resp) async {
Future<void> _handleWechatAuthResp(WeChatAuthResponse resp) async {
setState(() => _wechatLoading = false);
if (resp.errCode != 0 || resp.code == null) return;
if ((resp.errCode ?? -1) != 0 || resp.code == null) return;
try {
await AuthService.instance.loginByWechat(code: resp.code!);
if (mounted) Navigator.pushReplacementNamed(context, '/main');

View File

@ -56,7 +56,7 @@ Future<void> main() async {
// : https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Universal_Links/Universal_Links.html
const wechatAppId = String.fromEnvironment('WECHAT_APP_ID', defaultValue: '');
if (wechatAppId.isNotEmpty) {
await registerWxApi(appId: wechatAppId, universalLink: 'https://www.gogenex.com/wechat/');
await Fluwx().registerApi(appId: wechatAppId, universalLink: 'https://www.gogenex.com/wechat/');
}
//

View File

@ -26,7 +26,7 @@ dependencies:
qr_flutter: ^4.1.0
share_plus: ^10.0.2
flutter_secure_storage: ^9.2.2
fluwx: ^3.10.0
fluwx: ^5.0.0
tobias: ^3.0.0
google_sign_in: ^6.2.1
sign_in_with_apple: ^6.1.0