smfitui_fl_plugin 0.1.5+1
smfitui_fl_plugin: ^0.1.5+1 copied to clipboard
SMFitUI flutter plugin
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:smfitui_fl_plugin/custom_exercise.dart';
import 'package:smfitui_fl_plugin/custom_workout.dart';
import 'package:smfitui_fl_plugin/smfitui_fl_delegate.dart';
import 'package:smfitui_fl_plugin/smfitui_fl_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> implements SMFitUIFlPluginDelegate{
bool _didSuccess = false;
final _smfituiFlPlugin = SMFitUIFLPlugin();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
bool didSuccess;
if (!mounted) return;
var result = await _smfituiFlPlugin.configSMFit("YOUR_KEY");
didSuccess = result.$1;
_smfituiFlPlugin.delegate = this;
setState(() {
_didSuccess = didSuccess;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Auth accepted: $_didSuccess\n'),
TextButton(onPressed: startCustomWorkout, child: const Text("Start Custom Workout")),
],
)
),
),
);
}
void startCustomWorkout() async {
// Call this function to start the session
CustomWorkout workout = CustomWorkout(
[
CustomExercise("Knees", null, 19, 11, [UIElements.timer, UIElements.repsCounter], "HighKnees"),
CustomExercise(null, null, 5, null, [UIElements.timer], "Cooldown"),
]
);
String? error = await _smfituiFlPlugin.startCustomWorkout(workout);
print("Start custom workout error: ${error ?? "non"}");
}
@override
void didExitWorkout(WorkoutSummaryData summary) {
print("didExitWorkout $summary");
}
@override
void workoutDidFinish(WorkoutSummaryData summary) {
print("workoutDidFinish $summary");
}
@override
void handleWorkoutErrors(String error) {
print("handleWorkoutErrors $error");
}
}