Our GOFA SDK uses GetIt to register our GofaPoseSdkManager as a singleton service, which helps with initialization of our SDK functionalities.
So please run the following command to add the dependencies:
flutter pub add get_it
flutter pub add provider
flutter pub add bloc
flutter pub add flutter_blocUse the same member authentication as Lessons and WebView. First define the backend token provider and stable member ID as shown in SDK authentication.
import 'package:gofa_pose/gofa_pose.dart';
import 'package:get_it/get_it.dart';
final pose = GofaPoseSdkManager();
await pose.init(
environment: Environment.UAT,
clientId: yourUatClientId,
clientUserId: existingStableMemberId,
customTokenProvider: provider,
);
if (!pose.isInitialized) throw StateError('Challenge not initialized');
GetIt.I.registerSingleton<GofaPoseSdkManager>(pose);
// Open the Challenge screen only after successful initialization.Challenge may initialize first or run alone. Keep the same environment, member and provider across modules. Handle sign-in errors in your host app before opening a protected screen. Follow the shared logout instructions on the authentication page.
Because our gofa_pose depends on Firebase connection to be established in order to run successfully, we highly recommend you to add the following FutureBuilder to your widget tree where you will compose our widgets and BloC.
FutureBuilder(
future: GetIt.I.allReady(),
builder: (context, snapshot) {
// build any widget that composes Gofa Screen and Bloc Logic
if (!snapshot.hasData) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
),
);
}
return const YourWidget();
},
)Since version v2.0.0, the locales of our supported languages are:
Locale('en'),
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'),
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'),You are required to add GofaLocalizationsDelegate() to the localizationsDelegates array list of your MaterialApp.
MaterialApp(
...
localizationsDelegates: const [
AppLocalizations.delegate,
...
GofaLocalizationsDelegate(),
],
locale: currentLocale,
supportedLocales: yourSupportedLocales,
// supportedLocales: GofaLocalizations.supportedLocales,
...
)Warning No need since v1.0.18. Remove these dependencies if you are using gofa_pose v1.0.18 or later versions.
Add the following android dependencies:
dependencies {
...
// GS-152 Fatal error: ProcessLifecycleOwner - when starting workout set.
// ref: https://developer.android.com/jetpack/androidx/releases/lifecycle
def lifecycle_version = "2.6.1"
def arch_version = "2.2.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// ViewModel utilities for Compose
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// Lifecycle utilities for Compose
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
}Warning No need since v2.0.0. Remove these code if you are using v2.0.0 or later.
MultiProvider(
providers: [
...
]
)Warning No need since v2.0.0. Remove these code if you are using v2.0.0 or later.
// Provider for AudioManager
ChangeNotifierProvider<AudioManager>(
create: (context) => AudioManager(),
lazy: false,
),Warning No need since v2.0.0. Remove these code if you are using v2.0.0 or later.
BlocProvider(
create: (context) => WorkoutSetBloc(
context.read<AudioManager>(),
),
lazy: false,
),Warning You will need to navigate to our WorkoutSetScreen. In order for our screen to gain access to the WorkoutSetBloc, please make sure it is provided before the MaterialApp, so that any newly pushed page (WorkoutSetScreen, or your pages) can access WorkoutSetBloc too.
Below is a working example code for your reference.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
// Provider for AudioManager
ChangeNotifierProvider<AudioManager>(
create: (context) => AudioManager(),
lazy: false,
),
BlocProvider(
create: (context) => WorkoutSetBloc(
context.read<AudioManager>(),
),
lazy: false,
),
],
builder: (context, child) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
...existing code...