import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.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, ); // Bu widget'ı görsele dönüştürmek için çizimi başlatıyoruz final renderObject = boundaryKey.currentContext?.findRenderObject(); if (renderObject is RenderRepaintBoundary) { final image = await renderObject.toImage(pixelRatio: 3.0); // Yüksek çözünürlük için pixelRatio ayarlayın 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}; }