shyun_link 2.1.0
shyun_link: ^2.1.0 copied to clipboard
A comprehensive deeplink and short URL management system with ultra-simple ShyunLinkManager API. Built with Clean Architecture principles, supports strategy patterns, dependency injection, and enterpr [...]
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:shyun_link/shyun_link.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the ShyunLink system
await _initializeShyunLink();
runApp(ExampleApp());
}
Future<void> _initializeShyunLink() async {
// Create configuration
final config = ShyunLinkConfig.defaults(
appScheme: 'myapp',
webBaseUrl: 'https://example.com',
apiServerUrl: 'https://api.example.com',
shortLinkDomain: 'short.ly',
pathMappings: {
'store': '/storeDetail?id={id}',
'product': '/product/{id}',
'profile': '/user/{id}',
'curation': '/curationDetail?type={type}&id={id}',
'gift': '/giftcode?code={code}',
},
fallbackUrls: {
'store': 'https://example.com/stores',
'product': 'https://example.com/products',
'profile': 'https://example.com/profiles',
'default': 'https://example.com/',
},
);
ShyunLink.initialize(config: config);
}
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ShyunLink Example',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late final ShyunLinkService _shyunLink;
String _lastShortLink = 'None';
@override
void initState() {
super.initState();
_shyunLink = ShyunLink.service;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ShyunLink Example'),
elevation: 0,
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildInfoCard(),
SizedBox(height: 20),
_buildGenericLinkSection(),
SizedBox(height: 20),
_buildSharingSection(),
SizedBox(height: 20),
_buildBatchOperationSection(),
],
),
),
);
}
Widget _buildInfoCard() {
return Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'ShyunLink',
style: Theme.of(context).textTheme.headlineSmall,
),
SizedBox(height: 8),
Text(
'Generic deeplink and short URL management system.',
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
);
}
Widget _buildGenericLinkSection() {
return Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Generic Link Creation',
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(height: 16),
Text('Last created: $_lastShortLink'),
SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
ElevatedButton(
onPressed: () => _createStoreLink(123),
child: Text('Store Link'),
),
ElevatedButton(
onPressed: () => _createProductLink(456),
child: Text('Product Link'),
),
ElevatedButton(
onPressed: () => _createCurationLink(),
child: Text('Curation Link'),
),
ElevatedButton(
onPressed: () => _createGiftLink(),
child: Text('Gift Code Link'),
),
ElevatedButton(
onPressed: () => _createAppLink(),
child: Text('App Promotion'),
),
],
),
],
),
),
);
}
Widget _buildSharingSection() {
return Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Sharing Functions',
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
ElevatedButton(
onPressed: () => _shareStore(),
child: Text('Share Store'),
),
ElevatedButton(
onPressed: () => _shareProduct(),
child: Text('Share Product'),
),
ElevatedButton(
onPressed: () => _shareCustom(),
child: Text('Share Custom'),
),
],
),
],
),
),
);
}
Widget _buildBatchOperationSection() {
return Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Batch Operations',
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _createBatchLinks,
child: Text('Create Batch Links'),
),
],
),
),
);
}
// Generic Link Creation Methods
Future<void> _createStoreLink(int storeId) async {
try {
final request = GenericLinkRequest.store(storeId);
final shortUrl = await _shyunLink.createShortLink(request);
setState(() {
_lastShortLink = shortUrl;
});
_showSnackBar('Store link created: $shortUrl', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create store link: $e');
}
}
Future<void> _createProductLink(int productId) async {
try {
final request = GenericLinkRequest.custom(
type: 'product',
id: productId,
);
final shortUrl = await _shyunLink.createShortLink(request);
setState(() {
_lastShortLink = shortUrl;
});
_showSnackBar('Product link created: $shortUrl', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create product link: $e');
}
}
Future<void> _createCurationLink() async {
try {
final request = GenericLinkRequest.curation(
curationType: 'event',
id: 789,
);
final shortUrl = await _shyunLink.createShortLink(request);
setState(() {
_lastShortLink = shortUrl;
});
_showSnackBar('Curation link created: $shortUrl', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create curation link: $e');
}
}
Future<void> _createGiftLink() async {
try {
final request = GenericLinkRequest.giftCode('GIFT123');
final shortUrl = await _shyunLink.createShortLink(request);
setState(() {
_lastShortLink = shortUrl;
});
_showSnackBar('Gift link created: $shortUrl', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create gift link: $e');
}
}
Future<void> _createAppLink() async {
try {
final request = GenericLinkRequest.appPromotion(
originalUrl: 'https://example.com/download',
);
final shortUrl = await _shyunLink.createShortLink(request);
setState(() {
_lastShortLink = shortUrl;
});
_showSnackBar('App link created: $shortUrl', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create app link: $e');
}
}
// Sharing Methods
Future<void> _shareStore() async {
try {
await _shyunLink.share(
type: 'store',
id: 123,
shareText: '맛집 추천! 꼭 가보세요!',
);
_showSnackBar('Store shared successfully!', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to share store: $e');
}
}
Future<void> _shareProduct() async {
try {
final request = GenericLinkRequest.custom(
type: 'product',
id: 456,
);
await _shyunLink.shareLink(
request: request,
shareText: 'Check out this amazing product!',
);
_showSnackBar('Product shared successfully!', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to share product: $e');
}
}
Future<void> _shareCustom() async {
try {
await _shyunLink.share(
type: 'custom',
metadata: {'category': 'special', 'event': 'launch'},
shareText: 'Special event is live!',
);
_showSnackBar('Custom content shared successfully!', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to share custom content: $e');
}
}
// Batch Operations
Future<void> _createBatchLinks() async {
try {
final requests = [
GenericLinkRequest.store(101),
GenericLinkRequest.store(102),
GenericLinkRequest.custom(type: 'product', id: 201),
GenericLinkRequest.giftCode('BATCH123'),
];
final urls = await _shyunLink.createShortLinks(requests);
_showSnackBar('Created ${urls.length} batch links successfully!', isSuccess: true);
} catch (e) {
_showSnackBar('Failed to create batch links: $e');
}
}
void _showSnackBar(String message, {bool isSuccess = false}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: isSuccess ? Colors.green : Colors.red,
),
);
}
}