hamuga_id_sdk 0.0.10
hamuga_id_sdk: ^0.0.10 copied to clipboard
A Flutter package that provides a HamugaIdButton widget for easy integration with Hamuga ID authentication.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:hamuga_id_sdk/hamuga_id_sdk.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
HamugaId.initialize(
const HamugaIdConfig(
clientId: 'b5c7169f-9413-4e1c-a056-2a33771591e0',
redirectUri: 'hamugaidsdkflutter://callback',
scopes: [HamugaIdScope.phone, HamugaIdScope.openid],
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hamuga ID SDK Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightBlue),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? _authCode;
String? _error;
@override
void initState() {
super.initState();
// 1. Start listening for the deep link response
HamugaId.instance.onAuthResponse.listen((response) {
debugPrint('Hamuga ID Response: $response');
setState(() {
if (response.isSuccess) {
_authCode = response.code;
_error = null;
} else {
_error =
response.errorDescription ?? response.error ?? 'Unknown error';
_authCode = null;
}
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Hamuga ID SDK Example'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Hamuga ID Authentication',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 32),
// 2. Use the pre-styled button
HamugaIdButton(
onPressed: () {
debugPrint('Auth button pressed');
},
),
const SizedBox(height: 32),
const Divider(),
const SizedBox(height: 32),
if (_authCode != null) ...[
const Text(
'Successfully Authenticated!',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
SelectableText('Auth Code: $_authCode'),
] else if (_error != null) ...[
Text(
'Error: $_error',
style: const TextStyle(color: Colors.red),
),
] else
const Text('Not authenticated yet.'),
const SizedBox(height: 48),
// 3. Example of manual trigger
OutlinedButton.icon(
onPressed: () {
HamugaId.instance.signIn();
},
icon: const Icon(Icons.open_in_browser),
label: const Text('Manual Auth Trigger'),
),
],
),
),
),
);
}
}