- 21 Feb 2024
- 1 Minute to read
- Print
- DarkLight
Flutter - SMFitUI plugin
- Updated on 21 Feb 2024
- 1 Minute to read
- Print
- DarkLight
SMFitUI package
Introduction
This article is a step-by-step guide to how to integrate the smfitui_fl_plugin into your Flutter application.
Installation
In order to install thesmfitui_fl_pluginpackage run this code in the application terminal.
flutter pub add smfitui_fl_plugin
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):
dependencies:
smfitui_fl_plugin: ^0.1.0+1
In your Podfile (should be in app_name/ios) add the sources in the file header
source 'https://github.com/CocoaPods/Specs.git'
source 'https://bitbucket.org/sency-ios/sency_ios_sdk.git'
also add these install hooks
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.5'
end
end
end
Configuration
To work with the SDK you should configure the package (function will throw an error if we skip this stage).
In your first app screen import the package:
import 'package:smfitui_fl_plugin/smfitui_fl_plugin.dart';
Thenadd the following code in State class:
class _MyAppState extends State<MyApp> {
bool _didSuccess = false;
final _smfituiFlPlugin = SMFitUIFLPlugin();
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
bool didSuccess;
// Before doing anything you need to call configSMFit with your key and wait for the result if not you will not be able to access plugin functions
var result = await _smfituiFlPlugin.configSMFit("YOUR_KEY");
didSuccess = result.$1;
if (!mounted) return;
setState(() {
_didSuccess = didSuccess;
});
}
}
Implement SMFitUI callbacks
Implement SMFitUIFlPluginDelegate
class _MyAppState extends State<MyApp> implements SMFitUIFlPluginDelegate{
then add this functions
@override
void didExitWorkout(WorkoutSummaryData summary) {
print("didExitWorkout $summary");
}
@override
void workoutDidFinish(WorkoutSummaryData summary) {
print("workoutDidFinish $summary");
}
@override
void handleWorkoutErrors(String error) {
print("handleWorkoutErrors $error");
}
- didExitWorkout - This function will be called when the user exit the SDK without finishing the workout
- workoutDidFinish - This function will be called when the user finish the exercise
- handleWorkoutErrors -This function will be calledwhen a Error occurred
Starting the SDK
To start a Custom Workout we will need to first create a CustomWorkout with array of CustomExercise
CustomWorkout workout = CustomWorkout(
[
CustomExercise("Knees", null, 19, 11, [UIElements.timer, UIElements.repsCounter], "HighKnees"),
CustomExercise(null, null, 5, null, [UIElements.timer], "Cooldown"),
]
);
- CustomExercise:
- named - set this value if you want to name the workout something else
- instruction - if you want to add custom exercise instruction add a String url of the mp3 sound
- totalSeconds - the total second of the exercise
- totalReps - the amount of reps
- uiElements - array of UIElement you want to present
- timer
- repsCounter
- type - The exercise type
- Go to Sency's exercise library to view the currently supported exercise types
Now we can start the SDK
String? error = await _smfituiFlPlugin.startCustomWorkout(workout);
print("Start custom workout error: ${error ?? "non"}");