Flutter面试题——Redux之项目实战(8)

一 概述

  1. 招聘平台场景:Redux 状态管理架构设计
  2. 教育平台场景:Redux 状态建模 + 权限系统
  3. 直播/聊天类应用:Redux + WebSocket 架构
  4. Redux 架构中常用“中间件模板”大全(可快速复用)
  5. Flutter Redux + 动态表单配置架构(面向低代码需求)
  6. Redux 项目演示/作品集如何打磨出色?

二 面试题解答(仅供参考)

2.1 招聘平台场景:Redux 状态管理架构设计

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
1、典型模块
-用户模块:登录、注册、简历信息、收藏记录
-职位模块:职位列表、职位详情、搜索筛选
-消息模块:企业私信通知、聊天
-系统模块:权限、主题切换、本地缓存、版本更新

2、状态模型设计示意
class AppState {
final AuthState auth;
final ResumeState resume;
final JobListState jobList;
final ChatState chat;
final SettingsState settings;
}

3、Action 示例
class FetchJobListAction {}
class ToggleFavoriteJobAction { final String jobId; }
class UpdateResumeSectionAction { final ResumeSection section; }

4、中间件用法
-authMiddleware: 登录鉴权、刷新 token
-jobMiddleware: 搜索防抖,关键词推荐
-chatMiddleware: WebSocket 接收 + 未读消息统计

5、页面跳转权限控制
中间件中拦截导航 Action:

void navigationMiddleware(Store store, action, NextDispatcher next) {
if (action is NavigateToResumeEditAction &&
!store.state.auth.isLoggedIn) {
store.dispatch(ShowLoginRequiredDialogAction());
return;
}
next(action);
}

2.2 教育平台场景:Redux 状态建模 + 权限系统

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
1、模块划分建议
-用户:学生、教师、管理员
-课程:报名、上课记录、成绩、作业
-消息:站内信、公告推送
-系统:国际化、主题切换

2、典型状态设计
class AppState {
final UserState user;
final CourseState course;
final MessageState message;
final AppSettings settings;
}

3、多角色权限建议
3.1 使用枚举和权限 map 建模:

enum UserRole { student, teacher, admin }
class UserState {
final UserRole role;
final Set<String> permissions;
}

3.2 判断权限:
if (!state.user.permissions.contains("course.edit")) {
return Text("无编辑权限");
}

权限粒度由后端下发,Redux 中保存后统一判断。支持动态配置权限体系。

2.3 直播/聊天类应用:Redux + WebSocket 架构

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
1、状态设计核心点
class ChatState {
final List<Message> messages;
final int unreadCount;
final bool socketConnected;
}

2、事件流转设计(Redux Action)
UI 输入 -> SendMessageAction
SendMessageMiddleware -> WebSocket 发送
WebSocket 接收 -> OnMessageReceivedAction
Reducer 更新 ChatState -> UI 渲染

3、WebSocket 中间件模式
class ChatMiddleware extends MiddlewareClass<AppState> {
final WebSocketClient client;

ChatMiddleware(this.client) {
client.onMessage = (msg) {
store?.dispatch(OnMessageReceivedAction(msg));
};
}

Store<AppState>? store;

@override
void call(Store<AppState> store, action, NextDispatcher next) {
this.store = store;
if (action is SendMessageAction) {
client.send(action.msg);
}
next(action);
}
}

2.4 Redux 架构中常用“中间件模板”大全(可快速复用)

模板名称 说明
authMiddleware 统一处理 token 刷新、未登录跳转
analyticsMiddleware 打点收集,每个 Action 分发时记录埋点日志
debounceMiddleware 搜索防抖、表单防连点提交
errorMiddleware 捕捉异常 Action,统一上报 + UI 提示
avigationMiddleware 封装所有页面跳转为 Action,脱离 Navigator.push 逻辑
socketMiddleware 实时通信,统一接入 WebSocket 客户端

2.5 Flutter Redux + 动态表单配置架构(面向低代码需求)

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
场景:如企业审批、教育作业、医疗表单等都可通过表单模板 + Redux 动态驱动页面。

1、表单 JSON 配置
{
"formId": "job_application",
"fields": [
{"type": "text", "label": "姓名", "key": "name"},
{"type": "dropdown", "label": "学历", "key":
"degree", "options": ["本科", "硕士"]},
{"type": "file", "label": "简历附件", "key": "resume"}
]
}

2、Redux 中状态设计

class FormState {
final String formId;
final Map<String, dynamic> values;
final Map<String, String> validationErrors;
}

动态构建表单 UI:
StoreConnector<AppState, FormState>(
converter: (store) => store.state.form,
builder: (context, formState) {
return DynamicFormBuilder(config, formState);
},
)

通过 UpdateFormFieldAction 动态更新状态,自动完成状态收集和提交逻辑。

2.6 Redux 项目演示/作品集如何打磨出色?

方面 建议
架构清晰 展示 Store / State / Action / Middleware 结构图
工程实践 展示状态持久化、模块解耦、权限控制方案
技术亮点 演示 DevTools、时间旅行、热更新 reducer
UI 演示 展示状态响应式更新、多模块交互过程(如:登录后跳转、收藏职位刷新)
文档 README 写明技术选型、Redux 使用规范、Action 命名规则、状态设计原则
线上 DEMO 推荐部署到 Firebase Hosting / GitHub Pages 方便面试官体验