Code Setup
Add the required packages for GOFA SDK
Our GOFA SDK uses GetIt to register our LessonSdkManager 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
Set up LessonSdkManager with init()
To initialize our Gofa Lesson SDK, you need to pass arguments:
- environment
- Please use
Environment.UATfor staging environment andEnvironment.PRDfor production environment
- Please use
// import the enum Environment from gofa_types
enum Environment { DEV, UAT, PRD }
- params
clientUserId: the unique (anonymous) ID representing a user in your app.clientId: the client ID assigned by GOFA to you as the app owner integrating our SDK into your app.clientSecret: a secret known only to your application and our authorization server. It protects your resources by only granting tokens to authorized requestors.membershipTier: optional string to represent the membership tier the client user belongs to. E.g., VIP, regular. This parameter affects the availability of fitness contents accordingly. Defaults to "regular" if not specified.
Note Please ensure you have Node.js and npm installed before proceeding. If you encounter issues, contact the GOFA support team for assistance.
Examples of initializing our LessonSdkManager:
- In main()
void main() async {
// ensure flutter services are initialized
WidgetsFlutterBinding.ensureInitialized();
...
await GetIt.I.registerSingletonAsync<LessonSdkManager>(
() async => await LessonSdkManager().init(
environment: Environment.UAT, // or Environment.PRD
params: {
'clientUserId': 'gofa_tester',
'clientId': 'abc',
'clientSecret': 'abcSecretKey123',
'membershipTier': 'VIP', // default to "regular" if not specified
},
// see "Data Exchange" > "In-app Callback Events" for instructions
updateCallback: lessonSdkUpdateCallback,
),
);
...
runApp(MyApp());
}
- During onPressed of the Entry Button to navigate to our GOFA Lessons
ElevatedButton(
onPressed: () {
if (!GetIt.I.isRegistered<LessonSdkManager>()) {
// create an instance of LessonSdkManager
final lessonSdkManager = LessonSdkManager();
GetIt.I.registerSingleton<LessonSdkManager>(lessonSdkManager);
}
final lessonSdkManager = GetIt.I<LessonSdkManager>();
// do not await when calling .init(), so that the app can immediately
// navigate to our splash screen
LessonSdkManager().init(
environment: Environment.UAT, // or Environment.PRD
params: {
'clientUserId': 'gofa_tester',
'clientId': 'abc',
'clientSecret': 'abcSecretKey123',
'membershipTier': 'VIP', // default to "regular" if not specified
},
// see "Data Exchange" > "In-app Callback Events" for instructions
updateCallback: lessonSdkUpdateCallback,
);
// You may pushNamed or just push.
// e.g. Navigator.pushNamed(context, GofaLessons.routeName);
// If pushNamed, remember to add the route:
// routes: {
// GofaLessons.routeName: (context) => const GofaLessons(),
// }
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const GofaLessons(
locale: Locale.fromSubtags(
languageCode: 'zh', scriptCode: 'Hant'),
),
),
);
},
child: const Text('GOFA Lessons'),
)
Add Gofa SDK language support
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 GofaLessonLocalizationsDelegate() to the localizationsDelegates array list of your MaterialApp.
MaterialApp(
...
localizationsDelegates: const [
AppLocalizations.delegate,
...
GofaLessonLocalizationsDelegate(),
],
locale: currentLocale,
supportedLocales: yourSupportedLocales,
// supportedLocales: GofaLocalizations.supportedLocales,
...
)