flutter_workoutkit 0.0.5 copy "flutter_workoutkit: ^0.0.5" to clipboard
flutter_workoutkit: ^0.0.5 copied to clipboard

A Flutter plugin that leverages Apple's WorkoutKit SDK to create, preview, and sync custom workouts with the Apple Watch Workout app.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_workoutkit/workoutkit.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _workoutkitPlugin = Workoutkit();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await _workoutkitPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;
    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter WorkoutKit Example'),
        ),
        body: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: ElevatedButton(
                      onPressed: () =>
                          _workoutkitPlugin.requestHealthPermissions(),
                      child: const Text('Request Health Permissions'),
                    ),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: Center(
                      child: Text('Running on: $_platformVersion\n'),
                    ),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSwimBikeRunWorkout,
                        buttonTitle: '[SwimBikeRun] Triathlon Training'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: samplePacerHoursWorkout,
                        buttonTitle: '[Pacer] 2 Hour Cycle'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: samplePacerMinutesWorkout,
                        buttonTitle: '[Pacer] 30 Minute Run'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSpeedCyclingWorkout,
                        buttonTitle: '[Custom] Speed Cycling'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleCustomWorkout,
                        buttonTitle: '[Custom] Timed Workout'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sample10kTrainingRun,
                        buttonTitle: '[Custom] 10k Training Run'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sample21kmTrainingRun,
                        buttonTitle: '[Custom] 21k Stepped Run'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSingleGoalTimedWorkout,
                        buttonTitle: '[Single] Timed Workout'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSingleGoalEnergyWorkout,
                        buttonTitle: '[Single] Energy Workout'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSingleOpenWorkout,
                        buttonTitle: '[Single] Open Workout'),
                  ),
                  Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: WorkoutPreviewButton(
                        workout: sampleSingleGoalSwimmingWorkout,
                        buttonTitle: '[Single] Swimming Workout'),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
5
likes
0
points
159
downloads

Publisher

verified publisheradamkramer.dev

Weekly Downloads

A Flutter plugin that leverages Apple's WorkoutKit SDK to create, preview, and sync custom workouts with the Apple Watch Workout app.

Homepage
Repository (GitHub)
View/report issues

Topics

#workoutkit #apple-watch #healthkit #fitness #workouts

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_workoutkit