Как я могу создать приложение подсчета шагов во флаттере - PullRequest
0 голосов
/ 04 ноября 2019

Я хочу создать приложение для подсчета шагов, используя флаттер. Я не уверен, как я могу это сделать. Пожалуйста, помогите мне

Я пытался использовать некоторые пакеты, но они не работают`

Я использовал этот пакет: https://pub.dev/packages/flutter_pedometer#-readme-tab-

Когда я запускаю приложение в центре, онопоказывает общее количество выполненных шагов и затем неизвестных, шаги не обновляются

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

import 'package:flutter_pedometer/flutter_pedometer.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _stepCountValue = 'Unknown';
  StreamSubscription<int> _subscription;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    FlutterPedometer pedometer = new FlutterPedometer();
    _subscription = pedometer.stepCountStream.listen(_onData,
        onError: _onError, onDone: _onDone, cancelOnError: true);

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
  }

  void _onData(int stepCountValue) async {
    print(stepCountValue);

    setState(() {
      _stepCountValue = "$stepCountValue";
    });
  }

  void _onDone() {}

  void _onError(error) {
    print("Flutter Pedometer Error: $error");
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new Text('Steps taken: $_stepCountValue\n'),
        ),
      ),
    );
  }
}


...