pedometer 0.0.3 copy "pedometer: ^0.0.3" to clipboard
pedometer: ^0.0.3 copied to clipboard

outdated

A pedometer plugin for retrieving the steps taken today. Works for both iOS and Android and is written in Swift/Java.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:pedometer/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 {
    Pedometer pedometer = new Pedometer();
    _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'),
        ),
      ),
    );
  }
}
257
likes
0
pub points
96%
popularity

Publisher

verified publishercachet.dk

A pedometer plugin for retrieving the steps taken today. Works for both iOS and Android and is written in Swift/Java.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on pedometer