Files
feature-next-arch/lib/features/v2/report/USAGE_EXAMPLE.md

1.9 KiB

现场上报模块 - 使用示例

1. 在路由中注册

在你的路由配置文件(如 lib/core/router/app_router.dart)中添加:

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/features/v2/report/report.dart';

// 在 routes 列表中添加
GoRoute(
  path: '/report',
  builder: (context, state) => BlocProvider(
    create: (context) => ReportDependencyInjector.createReportCubit(),
    child: const ReportPage(),
  ),
),

2. 跳转到上报页面

在任何页面中,使用以下方式跳转:

import 'package:go_router/go_router.dart';

// 跳转到上报页面
context.push('/report');

3. 完整示例

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class SomePage extends StatelessWidget {
  const SomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('示例页面')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            // 跳转到现场上报页面
            context.push('/report');
          },
          child: const Text('现场上报'),
        ),
      ),
    );
  }
}

4. 依赖说明

必需依赖(项目已包含)

  • flutter_bloc: ^9.1.1
  • equatable: ^2.0.8
  • fpdart: ^1.2.0
  • go_router: ^17.0.1

可选依赖(按需添加)

如果需要实现真实的图片/视频上传功能,需要添加:

dependencies:
  image_picker: ^1.1.2

5. 注意事项

  1. 确保在跳转前已经配置好路由
  2. BlocProvider 必须在 ReportPage 的父级
  3. 当前使用模拟数据,可直接运行测试
  4. 所有常量已抽取,便于主题定制

6. 后续开发

对接真实 API 时,修改 lib/features/v2/report/data/datasources/report_remote_datasource_impl.dart 文件即可。