174 lines
5.2 KiB
Dart
174 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import '../../services/notification_service.dart';
|
|
|
|
class ProfilePage extends StatefulWidget {
|
|
@override
|
|
_ProfilePageState createState() => _ProfilePageState();
|
|
}
|
|
|
|
class _ProfilePageState extends State<ProfilePage> {
|
|
String? fcmToken;
|
|
final TextEditingController _tokenController = TextEditingController();
|
|
bool isLoading = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadFCMToken();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tokenController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _loadFCMToken() async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
|
|
try {
|
|
final token = await NotificationService().getToken();
|
|
setState(() {
|
|
fcmToken = token;
|
|
_tokenController.text = token ?? 'Token not available';
|
|
isLoading = false;
|
|
});
|
|
} catch (e) {
|
|
setState(() {
|
|
fcmToken = null;
|
|
_tokenController.text = 'Error loading token: $e';
|
|
isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
Future<void> _copyToClipboard() async {
|
|
if (fcmToken != null && fcmToken!.isNotEmpty) {
|
|
await Clipboard.setData(ClipboardData(text: fcmToken!));
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('FCM Token copied to clipboard'),
|
|
backgroundColor: Color(0xFF6A4C93),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
'Profile',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
backgroundColor: Colors.white,
|
|
foregroundColor: Color(0xFF6A4C93),
|
|
elevation: 0,
|
|
bottom: PreferredSize(
|
|
preferredSize: Size.fromHeight(1),
|
|
child: Container(
|
|
height: 1,
|
|
color: Colors.grey[200],
|
|
),
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Development Tools',
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF6A4C93),
|
|
),
|
|
),
|
|
SizedBox(height: 16),
|
|
|
|
Text(
|
|
'FCM Token:',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
SizedBox(height: 8),
|
|
|
|
if (isLoading)
|
|
Center(
|
|
child: CircularProgressIndicator(
|
|
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFF6A4C93)),
|
|
),
|
|
)
|
|
else
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey[300]!),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: TextField(
|
|
controller: _tokenController,
|
|
readOnly: true,
|
|
maxLines: 4,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontFamily: 'monospace',
|
|
),
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
contentPadding: EdgeInsets.all(12),
|
|
hintText: 'FCM Token will appear here...',
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 8),
|
|
|
|
Row(
|
|
children: [
|
|
ElevatedButton.icon(
|
|
onPressed: fcmToken != null ? _copyToClipboard : null,
|
|
icon: Icon(Icons.copy, size: 18),
|
|
label: Text('Copy Token'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Color(0xFF6A4C93),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 12),
|
|
OutlinedButton.icon(
|
|
onPressed: _loadFCMToken,
|
|
icon: Icon(Icons.refresh, size: 18),
|
|
label: Text('Refresh'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: Color(0xFF6A4C93),
|
|
side: BorderSide(color: Color(0xFF6A4C93)),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |