bug fix & share cont

This commit is contained in:
Juki-shiba 2025-02-21 15:23:35 +05:30
parent a1993712ac
commit dc3bfbbaaa
5 changed files with 86 additions and 65 deletions

View File

@ -2086,66 +2086,14 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
), ),
SizedBox(width: 5), SizedBox(width: 5),
GestureDetector( GestureDetector(
onTap: () async { onTap: () => shareCurrentPage(context),
try { child: SvgPicture.asset(
// Define share content UaeNumbersAssetPath.share,
final String shareLink = 'https://fcsc-da580.web.app'; // Your link semanticsLabel: 'share',
final String shareText = 'Check this out!';
final String svgAssetPath = 'assets/logos/fcsc.png'; // Your SVG asset path
// Create a controller to capture the SVG as an image
final screenshotController = ScreenshotController();
// Render the SVG off-screen and capture it as PNG
final svgWidget = SvgPicture.asset(
svgAssetPath,
width: 200, // Adjust size as needed
height: 200,
);
// Capture the SVG as a PNG
final Uint8List? capturedImage = await screenshotController.captureFromWidget(
Material(
child: svgWidget,
),
);
if (capturedImage == null) {
throw Exception('Failed to capture SVG as image');
}
// Save the captured PNG to a temporary file
final directory = await getTemporaryDirectory();
final file = File('${directory.path}/shared_image.png');
await file.writeAsBytes(capturedImage);
// Share the PNG file with text and link
await Share.shareXFiles(
[XFile(file.path)],
text: '$shareText\n$shareLink',
subject: 'Shared Content',
);
// Clean up temporary file
await file.delete();
} catch (e) {
print("Error sharing file: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error sharing: $e')),
);
}
},
child: Container(
width: 24, width: 24,
height: 24, height: 24,
child: Icon( )
Icons.share, ),
color: Colors.white,
size: 24,
semanticLabel: 'Share',
),
),
),
], ],
), ),
SizedBox( SizedBox(
@ -2741,7 +2689,47 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
); );
} }
} }
Future<void> shareCurrentPage(BuildContext context) async {
try {
// Get current route from go_router
final String currentRoute = GoRouterState.of(context).uri.toString();
final String baseAppLink = 'https://fcsc-da580.web.app';
final String shareLink = '$baseAppLink$currentRoute';
final String shareText = 'Check this out!';
final String svgAssetPath = 'assets/logos/fcsc.png';
final screenshotController = ScreenshotController();
final svgWidget = SvgPicture.asset(
svgAssetPath,
width: 200,
height: 200,
);
final Uint8List? capturedImage = await screenshotController.captureFromWidget(
Material(child: svgWidget),
);
if (capturedImage == null) {
throw Exception('Failed to capture SVG as image');
}
final directory = await getTemporaryDirectory();
final file = File('${directory.path}/shared_image.png');
await file.writeAsBytes(capturedImage);
await Share.shareXFiles(
[XFile(file.path)],
text: '$shareText\n$shareLink',
subject: 'Shared Content',
);
await file.delete();
} catch (e) {
print("Error sharing file: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error sharing: $e')),
);
}
}
// Function to convert hex color string to Color // Function to convert hex color string to Color
Color _getColorFromHex(String hexColor) { Color _getColorFromHex(String hexColor) {
hexColor = hexColor.replaceFirst('#', ''); hexColor = hexColor.replaceFirst('#', '');

View File

@ -1078,12 +1078,12 @@ class _BaseScaffoldState extends ConsumerState<BaseScaffold> {
} }
} }
} }
void _showLogoutConfirmationDialog(context) { void _showLogoutConfirmationDialog(BuildContext context) {
double myheight = MediaQuery.of(context).size.height; double myheight = MediaQuery.of(context).size.height;
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, // User must tap a button to dismiss dialog barrierDismissible: false, // User must tap a button to dismiss dialog
builder: (context) => AlertDialog( builder: (dialogContext) => AlertDialog(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0), // Rounded corners borderRadius: BorderRadius.circular(5.0), // Rounded corners
), ),
@ -1113,7 +1113,7 @@ void _showLogoutConfirmationDialog(context) {
SizedBox( SizedBox(
width: 120, // Set button width width: 120, // Set button width
child: TextButton( child: TextButton(
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(dialogContext),
style: TextButton.styleFrom( style: TextButton.styleFrom(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
@ -1135,9 +1135,9 @@ void _showLogoutConfirmationDialog(context) {
SizedBox( SizedBox(
width: 120, // Set button width width: 120, // Set button width
child: TextButton( child: TextButton(
onPressed: () { onPressed: () async {
Navigator.pop(context); await logout(dialogContext); // Pass dialogContext to logout
// Add logout function here Navigator.pop(dialogContext); // Close the dialog
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
backgroundColor: Color(0xFFAA8E83), // Background color backgroundColor: Color(0xFFAA8E83), // Background color
@ -1160,3 +1160,10 @@ void _showLogoutConfirmationDialog(context) {
); );
} }
Future<void> logout(BuildContext context) async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear(); // Clear shared preferences
context.go('/login'); // Navigate to the root route (e.g., login screen)
}

View File

@ -7,6 +7,7 @@ import Foundation
import connectivity_plus import connectivity_plus
import file_selector_macos import file_selector_macos
import firebase_core
import flutter_secure_storage_macos import flutter_secure_storage_macos
import package_info_plus import package_info_plus
import path_provider_foundation import path_provider_foundation
@ -19,6 +20,7 @@ import webview_flutter_wkwebview
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))

View File

@ -421,6 +421,30 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.9.3+3" version: "0.9.3+3"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
sha256: "26de145bb9688a90962faec6f838247377b0b0d32cc0abecd9a4e43525fc856c"
url: "https://pub.dev"
source: hosted
version: "2.32.0"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
sha256: d7253d255ff10f85cfd2adaba9ac17bae878fa3ba577462451163bd9f1d1f0bf
url: "https://pub.dev"
source: hosted
version: "5.4.0"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
sha256: e47f5c2776de018fa19bc9f6f723df136bc75cdb164d64b65305babd715c8e41
url: "https://pub.dev"
source: hosted
version: "2.21.0"
fixnum: fixnum:
dependency: transitive dependency: transitive
description: description:

View File

@ -34,7 +34,7 @@ dependencies:
csv: ^6.0.0 csv: ^6.0.0
excel: ^4.0.2 excel: ^4.0.2
intl: ^0.19.0 intl: ^0.19.0
# firebase_core: ^2.27.0 firebase_core: ^2.27.0
the_validator: ^2.0.0 the_validator: ^2.0.0
pocketbase: ^0.18.1 pocketbase: ^0.18.1
flutter_secure_storage: ^9.0.0 flutter_secure_storage: ^9.0.0