shyun_link 3.0.0
shyun_link: ^3.0.0 copied to clipboard
Streamlined deeplink and short URL management with Clean Architecture. Focused on core functionality - ShyunLinkManager.createShortLink() and deeplink handling with multiple URL format support.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:shyun_link/shyun_link.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 🎉 ShyunLinkManager로 5줄 초기화!
await ShyunLinkManager.initialize(
appScheme: 'myapp',
webBaseUrl: 'https://myapp.com',
apiServerUrl: 'https://api.myapp.com',
shortLinkDomain: 'myapp.ly',
onDeepLink: (context) {
debugPrint('🔗 딥링크 받음: $context');
},
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ShyunLink Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const MyHomePage(title: 'ShyunLink v3.0.0 Example'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _lastResult = 'No action yet';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Icon(Icons.link, size: 48, color: Colors.blue),
const SizedBox(height: 16),
const Text(
'ShyunLink v3.0.0 - New Template API',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
const Text(
'New Template Pattern: pageName + webUrl + appScheme',
style: TextStyle(color: Colors.grey),
),
const SizedBox(height: 16),
Text(
'Last Result: $_lastResult',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 14),
),
],
),
),
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: () => _createShortLink(),
child: const Text('Create Short Link'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _shareStore(),
child: const Text('Share Store'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _testDeepLink(),
child: const Text('Test Deep Link'),
),
],
),
),
),
);
}
Future<void> _createShortLink() async {
try {
final link = await ShyunLinkManager.createShortLink(
pageName: 'store',
pageType: 'store',
pageId: 12345,
);
setState(() {
_lastResult = link != null ? 'Short link created: $link' : 'Failed to create link';
});
} catch (e) {
setState(() {
_lastResult = 'Error: $e';
});
}
}
Future<void> _shareStore() async {
try {
// Create short link with new API
final link = await ShyunLinkManager.createShortLink(
pageName: 'store',
pageType: 'store',
pageId: 12345,
);
if (link != null) {
// In a real app, this would use share_plus package
setState(() {
_lastResult = 'Store link ready to share: $link';
});
} else {
setState(() {
_lastResult = 'Failed to create store link';
});
}
} catch (e) {
setState(() {
_lastResult = 'Error: $e';
});
}
}
Future<void> _testDeepLink() async {
try {
// Test new template pattern: myapp://store?type=store&id=12345
await ShyunLinkManager.processDeepLink('myapp://store?type=store&id=12345');
setState(() {
_lastResult = 'Deep link processed successfully';
});
} catch (e) {
setState(() {
_lastResult = 'Error: $e';
});
}
}
}