Files
geo_front/lib/screens/share_screen.dart
T

94 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import '../providers/share_provider.dart';
class ShareScreen extends StatelessWidget {
const ShareScreen({super.key});
@override
Widget build(BuildContext context) {
final authProvider = context.watch<AuthProvider>();
final shareProvider = context.watch<ShareProvider>();
return Scaffold(
appBar: AppBar(
title: const Text('Share Location'),
),
body: Center(
child: Card(
margin: const EdgeInsets.all(24),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Share Your Location',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
const Text(
'Create a share link to share your location with family',
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
if (shareProvider.shareId.isNotEmpty)
Column(
children: [
Text(
'Share ID: ${shareProvider.shareId}',
style: const TextStyle(
fontSize: 16,
color: Colors.blue,
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
// Copy to clipboard functionality
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Share ID copied to clipboard'),
),
);
},
child: const Text('Copy Share ID'),
),
],
)
else
ElevatedButton(
onPressed: shareProvider.isLoading
? null
: () async {
try {
await shareProvider.createShare(
authProvider.token,
55.7558, // Default Moscow coordinates
37.6173,
);
} catch (e) {
// Error is handled by provider
}
},
child: const Text('Create Share Link'),
),
if (shareProvider.error.isNotEmpty) ...[
const SizedBox(height: 16),
Text(
shareProvider.error,
style: const TextStyle(color: Colors.red),
),
],
],
),
),
),
),
);
}
}