apple_workout_scheduler 0.0.1
apple_workout_scheduler: ^0.0.1 copied to clipboard
This plugin can be used to push and schedule a workout for apple watch
example/lib/main.dart
import 'package:apple_workout_scheduler/entities/auth_response_enum.dart';
import 'package:apple_workout_scheduler_example/primary_button.dart';
import 'package:flutter/material.dart';
import 'package:apple_workout_scheduler/apple_workout_scheduler.dart';
import 'package:apple_workout_scheduler/entities/workout_model.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _appleWorkoutSchedulerPlugin = AppleWorkoutScheduler();
WorkoutAuthentication? authenticationStatus;
@override
void initState() {
super.initState();
_appleWorkoutSchedulerPlugin.getAuthorization().then((status) {
authenticationStatus = status;
setState(() {});
});
}
Future<void> requestAuthorization() async {
print('requestAuthorization');
authenticationStatus =
await _appleWorkoutSchedulerPlugin.requestAuthorization();
print(authenticationStatus?.name.toUpperCase() ?? "Unknown");
setState(() {});
}
Future<void> scheduleSimpleWorkout() async {
ExceriseModel exceriseModel = ExceriseModel(
title: 'New Workout',
sessions: [
SessionModel(
reps: 1,
workouts: [
Workout(
sessionType: SessionType.work,
goalType: SessionGoalType.distance,
goal: 2000,
)
],
),
SessionModel(
reps: 2,
workouts: [
Workout(
sessionType: SessionType.work,
goalType: SessionGoalType.distance,
goal: 3000,
),
Workout(
sessionType: SessionType.recovery,
goalType: SessionGoalType.distance,
goal: 1000,
),
],
)
],
date: DateTime.now(),
);
_appleWorkoutSchedulerPlugin.scheduleWorkout(exceriseModel);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 200),
Text(
'Status: ${authenticationStatus?.name.toUpperCase() ?? 'Unknown'}',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
),
const SizedBox(height: 20),
Align(
alignment: Alignment.topCenter,
child: PrimaryButton(
title: 'Request Authorization',
onTap: requestAuthorization,
),
),
const SizedBox(height: 20),
Align(
alignment: Alignment.topCenter,
child: PrimaryButton(
title: 'Schedule Workout',
onTap: scheduleSimpleWorkout,
),
),
],
),
),
);
}
}