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_blocExamples of initializing our GofaPoseSdkManager:
void main() async {
// ensure flutter services are initialized
WidgetsFlutterBinding.ensureInitialized();
...
await GetIt.I.registerSingletonAsync<GofaPoseSdkManager>(
() async => await GofaPoseSdkManager().init(),
);
...
runApp(MyApp());
}ElevatedButton(
onPressed: () {
if (!GetIt.I.isRegistered<GofaPoseSdkManager>()) {
// create an instance of GofaPoseSdkManager
final gofaPoseSdkManager = GofaPoseSdkManager();
GetIt.I.registerSingleton<GofaPoseSdkManager>(gofaPoseSdkManager);
}
final gofaPoseSdkManager = GetIt.I<GofaPoseSdkManager>();
// do not await when calling .init(), so that the app can immediately
// navigate to our splash screen
GofaPoseSdkManager().init();
// You may pushNamed or just push.
// e.g. Navigator.pushNamed(context, GofaChallenge.routeName);
// If pushNamed, remember to add the route:
// routes: {
// GofaChallenge.routeName: (context) => const GofaChallenge(),
// }
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const GofaChallenge(
locale: Locale.fromSubtags(
languageCode: 'zh', scriptCode: 'Hant'),
),
),
);
},
child: const Text('GOFA Challenge'),
)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...