web_page.dart
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:appframe/bloc/web_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebPage extends StatelessWidget {
const WebPage({super.key});
@override
Widget build(BuildContext context) {
final Map<String, dynamic>? extraData = GoRouterState.of(context).extra as Map<String, dynamic>?;
print("接收到的参数: $extraData");
var sessionCode = extraData?['sessionCode'];
var userCode = extraData?['userCode'];
var classCode = extraData?['classCode'];
var userType = extraData?['userType'];
var stuId = extraData?['stuId'];
print("sessionCode:$sessionCode");
return BlocProvider(
create: (context) =>
WebCubit(WebState(false, '界面加载中...', false, sessionCode, userCode, classCode, userType, stuId)),
child: BlocConsumer<WebCubit, WebState>(
builder: (context, state) {
return Scaffold(
appBar: AppBar(title: Text(state.title)),
body: state.loaded
? WebViewWidget(controller: context.read<WebCubit>().controller)
: const Center(child: CircularProgressIndicator()),
// 用于测试一下点击跳转路由
floatingActionButton: FloatingActionButton(
onPressed: () {
context.read<WebCubit>().goAuth();
},
child: const Icon(Icons.add),
),
);
},
listener: (context, state) {
print("web page listener -------------------------");
// 跳转到微信授权页面
if (state.needAuth) {
print("跳转到微信授权页面");
context.go("/wechatAuth");
}
},
),
);
}
}