simple_pedometer 0.0.1 copy "simple_pedometer: ^0.0.1" to clipboard
simple_pedometer: ^0.0.1 copied to clipboard

Simple pedometer plugin for flutter iOS app. This plugin allows you to get pedometer data between to specified datetime on iOS.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:simple_pedometer/simple_pedometer.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _steps = 0;

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

  Future<void> getSteps() async {
    int stepsInLast4Hours;

    final sensorsPermission = await Permission.sensors.request();

    if (sensorsPermission.isDenied) {
      return;
    }

    try {
      stepsInLast4Hours = await SimplePedometer.getSteps(
        from: DateTime.now().add(const Duration(hours: -4)),
        to: DateTime.now(),
      );
    } on PlatformException {
      stepsInLast4Hours = 0;
    }
    if (!mounted) return;

    setState(() {
      _steps = stepsInLast4Hours;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Steps in last 4 hours: $_steps\n'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            getSteps();
          },
          child: const Icon(Icons.refresh),
        ),
      ),
    );
  }
}
3
likes
120
pub points
56%
popularity

Publisher

verified publisherbookm.me

Simple pedometer plugin for flutter iOS app. This plugin allows you to get pedometer data between to specified datetime on iOS.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_pedometer