import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; class CustomNotification { static const MethodChannel _channel = MethodChannel('custom_notifications'); static Future show( Widget widget, { Duration duration = const Duration(seconds: 2), List? buttons, }) async { final imageBytes = await _widgetToImage(widget); if (imageBytes != null) { await _channel.invokeMethod('showNotification', { 'image': imageBytes, 'buttons': buttons?.map((b) => b.toMap()).toList(), }); } } static Future _widgetToImage(Widget widget) async { try { final boundaryKey = GlobalKey(); final boundary = RepaintBoundary( key: boundaryKey, child: widget, ); final renderObject = boundaryKey.currentContext?.findRenderObject(); if (renderObject is RenderRepaintBoundary) { final image = await renderObject.toImage(pixelRatio: 3.0); final byteData = await image.toByteData(format: ui.ImageByteFormat.png); return byteData?.buffer.asUint8List(); } } catch (e) { print("Hata: $e"); } return null; } } class NotificationButton { final String title; final String action; NotificationButton({required this.title, required this.action}); Map toMap() => {'title': title, 'action': action}; } class AnimatedNotificationWidget extends StatelessWidget { final String title; final VoidCallback onTap; const AnimatedNotificationWidget({super.key, required this.title, required this.onTap}); @override Widget build(BuildContext context) { return GestureDetector( onTap: onTap, child: AnimatedContainer( duration: Duration(seconds: 2), width: 100, height: 100, color: Colors.blue, child: Center(child: Text(title, style: TextStyle(color: Colors.white))), ), ); } }