flutter tracker 追踪者app,蓝牙疫情监控

liuyuqi-dellpc 69008302b8 go on 3 months ago
android cdb838802c 我的页面,登录页面功能完善 6 months ago
assets 50ef3b8f45 继续完善track页面 7 months ago
ios a9615666fc Automatic Commit By liuyuqi 7 months ago
lib 69008302b8 go on 3 months ago
test 419e0792cb 添加header 7 months ago
.gitignore a9615666fc Automatic Commit By liuyuqi 7 months ago
.metadata a9615666fc Automatic Commit By liuyuqi 7 months ago
README.md 11b4e15c97 基于google nearby实现 6 months ago
analysis_options.yaml a9615666fc Automatic Commit By liuyuqi 7 months ago
pubspec.lock 11b4e15c97 基于google nearby实现 6 months ago
pubspec.yaml 11b4e15c97 基于google nearby实现 6 months ago

README.md

flutter_tracker

追踪者app,基于蓝牙提供疫情追踪功能。

基于 google nearby 功能实现

google nearby 基于蓝牙,wifi,gps 等综合信息来发现周围用户:

1、用户注册登录

  void register() async {
    MessageModel messageModel = await LoginDao.register(_userName, _pwd);
    if (messageModel != null) {
      if (messageModel.success) {
        Navigator.of(context).pushNamed(Routes.loginPage);
      }
      AppUtil.buildToast(messageModel.msg);
    } else {
      AppUtil.buildToast("注册失败,请检查网络");
    }
  }
  void login() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();

    if (_formKey.currentState.validate()) {
      _formKey.currentState.save();
      LoginEntity loginEntity = await LoginDao.login(_username, _password);
      if (loginEntity.msgModel.success) {
        prefs.setString('username', _username);
        prefs.setString('password', _password);
        prefs.setBool('isLogin', true);
        Navigator.of(context).pushNamed(Routes.indexPage);
      }
      AppUtil.buildToast(loginEntity.msgModel.msg);
    }
  }
  void logout() async {
    var sharedPreferences = await SharedPreferences.getInstance();
    String token = sharedPreferences.getString("token");
    try {
      MessageModel messageModel = await LoginDao.logout(token);
      if (messageModel != null) {
        AppUtil.buildToast(messageModel.msg);
      }
    } catch (e) {
      AppUtil.buildToast("退出异常" + e.toString());
    }
    Navigator.of(context).pushNamed(Routes.loginPage);
    sharedPreferences.remove("token");
    sharedPreferences.setBool("isLogin", false);
  }

2、进入跟踪页面,用户点击追踪按钮,云端获取最近15天遇到的人(姓名,健康状态)。

    try {
      bool a = await Nearby().startAdvertising(
        currentUser.username,
        strategy,
        onConnectionInitiated: null,
        onConnectionResult: (id, status) {
          print(status);
        },
        onDisconnected: (id) {
          print('Disconnected $id');
        },
      );
      // 上传追踪数据
      SharedPreferences sharedPreferences =
          await SharedPreferences.getInstance();
      String token = sharedPreferences.getString("token");
      TrackDao.uploadContact(token);
      print('ADVERTISING ${a.toString()}');
    } catch (e) {
      print(e);
    }

3、开始周围追踪,上传当前用户遇到的人

  void startTrack(bool flag) async {
    try {
      bool a = await Nearby().startAdvertising(
        currentUser.username,
        strategy,
        onConnectionInitiated: null,
        onConnectionResult: (id, status) {
          print(status);
        },
        onDisconnected: (id) {
          print('Disconnected $id');
        },
      );
      // 上传追踪数据
      TrackDao.

      print('ADVERTISING ${a.toString()}');
    } catch (e) {
      print(e);
    }
    discovery();
  }

注意

1、flutter_blue 依赖min19,编译30,其他版本都会出错

2、 nearby_connections: ^1.0.3

3、需要 google service 服务,国内安卓系统有问题。