mobile_sign_language_translation 2.0.0
mobile_sign_language_translation: ^2.0.0 copied to clipboard
Mobile Sign Language Translation Flutter Package.
import 'package:flutter/material.dart';
import 'package:mobile_sign_language_translation/mobile_sign_language_translation.dart';
import 'showcase_page.dart';
/// 👉 SignForDeaf credentials, needed only for real sign-language videos.
///
/// Every other flow in this demo (enable/disable, tap-to-translate, sentence
/// splitting, the selection menu, sensitive-data blocking, theming, language,
/// event log) works without them.
///
/// Supply them at build time so no key ever lands in the repository:
///
/// ```sh
/// flutter run \
/// --dart-define=SIGNFORDEAF_API_KEY=... \
/// --dart-define=SIGNFORDEAF_API_URL=https://...
/// ```
///
/// In VS Code the `.vscode/launch.json` configurations at the repository root
/// already pass these — fill the values in there (that folder is git-ignored).
/// Editing the defaults below still works if you prefer, but do not commit
/// them.
const String kApiKey = String.fromEnvironment(
'SIGNFORDEAF_API_KEY',
defaultValue: 'YOUR_API_KEY',
);
const String kApiUrl = String.fromEnvironment(
'SIGNFORDEAF_API_URL',
defaultValue: 'YOUR_API_URL',
);
/// Origin identifying the calling app. Defaults to [kApiUrl] when left empty.
const String kOriginUrl = String.fromEnvironment('SIGNFORDEAF_ORIGIN_URL');
/// Dictionary / translator identifiers, which together name the signer.
///
/// Kept as a matched pair — 43/35 is Hesna (TSL); Kadir is 23/16, Jason 44/36
/// (BSL) and Owais 37/29 (ASL). The idle avatar follows whichever pair is in
/// use, so a mismatched one loops the wrong person while the translation
/// renders.
const String kFdid = String.fromEnvironment(
'SIGNFORDEAF_FDID',
defaultValue: '35',
);
const String kTid = String.fromEnvironment(
'SIGNFORDEAF_TID',
defaultValue: '43',
);
void main() => runApp(const SignForDeafDemoApp());
class SignForDeafDemoApp extends StatefulWidget {
const SignForDeafDemoApp({super.key});
@override
State<SignForDeafDemoApp> createState() => _SignForDeafDemoAppState();
}
class _SignForDeafDemoAppState extends State<SignForDeafDemoApp> {
// A single controller shared across the app (like RN's useSignLanguageContext).
final SignForDeafController _controller = SignForDeafController(
storage: SharedPreferencesSignForDeafStorage(),
);
// Live-editable personalization, driven by the "Personalization" section.
SignLanguage _language = SignLanguage.turkish;
Color _primaryColor = const Color(0xFF6750A4);
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// ScreenUtilInit-style root initialization: wrap once at the very top and
// the SDK is active on every screen, for any router. Re-keyed so a
// language/color change re-applies the config (the controller is external,
// so its state is preserved).
return SignForDeafInit(
key: ValueKey(Object.hash(_language, _primaryColor)),
controller: _controller,
config: SignForDeafConfig(
apiKey: kApiKey,
apiUrl: kApiUrl,
originUrl: kOriginUrl.isEmpty ? null : kOriginUrl,
fdid: kFdid,
tid: kTid,
language: _language,
theme: SignForDeafTheme(primaryColor: _primaryColor),
floatingButton: const FloatingButtonConfig(hintMaxShows: 2),
accessibility: const SignForDeafAccessibility(announceOnOpen: true),
),
onEvent: (e) => debugPrint('SignForDeaf event: ${e.type}'),
builder: (context, child) => MaterialApp(
title: 'SignForDeaf Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: _primaryColor),
useMaterial3: true,
),
home: ShowcasePage(
controller: _controller,
apiConfigured: kApiKey != 'YOUR_API_KEY',
language: _language,
onLanguageChanged: (l) => setState(() => _language = l),
primaryColor: _primaryColor,
onPrimaryColorChanged: (c) => setState(() => _primaryColor = c),
),
),
);
}
}