pluggy 0.0.4+1
pluggy: ^0.0.4+1 copied to clipboard
A Flutter package that provides general-purpose services, tools, and features for Flutter applications.
Pluggy #
Flutter uygulamaları için genel amaçlı servisler, araçlar ve özellikler sağlayan bir Flutter paketi.
Özellikler #
- AlertService: Uygulamanın herhangi bir yerinden SnackBar ve BottomSheet gösterme
- SmartAlert: Overlay üstünde sağ altta yığılan modern uyarılar
Kurulum #
pubspec.yaml
dosyanıza ekleyin:
dependencies:
pluggy: ^0.0.4
Hızlı Başlangıç #
// AlertService (GoRouter veya Navigator ile yapılandırın)
import 'package:pluggy/services/alert_service/alert_service.dart';
import 'package:pluggy/services/alert_service/alert_service_config.dart';
// SmartAlert
import 'package:pluggy/services/alert_service/smart_alert.dart';
void main() {
// SmartAlert için navigatorKey gerekli
final navigatorKey = GlobalKey<NavigatorState>();
SmartAlert.init(navigatorKey);
// AlertService için: GoRouter context'i veya navigatorKey verin
// AlertServiceConfig().initialize(context: context); // MaterialApp.router içinde
// veya
// AlertServiceConfig().initialize(navigatorKey: navigatorKey);
runApp(MaterialApp(
navigatorKey: navigatorKey,
home: const MyHomePage(),
));
}
void examples(BuildContext context) {
// AlertService
AlertService.showSnackBar("Merhaba Dünya!", context: context);
// SmartAlert
SmartAlert.show(AlertType.success, 'Başarılı', 'İşlem tamamlandı');
}
Kullanım #
AlertService #
GoRouter ile (Önerilen)
import 'package:pluggy/services/alert_service/alert_service.dart';
import 'package:pluggy/services/alert_service/alert_service_config.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// AlertService'i GoRouter context ile başlatın
AlertServiceConfig().initialize(context: context);
return MaterialApp.router(
// ... diğer konfigürasyonlar
);
}
}
// Kullanım
void showMessage() {
AlertService.showSnackBar("Merhaba Dünya!");
AlertService.showBottomSheet("Başlık", "Mesaj");
}
Navigator ile (Eski yöntem)
import 'package:pluggy/services/alert_service/alert_service.dart';
import 'package:pluggy/services/alert_service/alert_service_config.dart';
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
// AlertService'i Navigator key ile başlatın
AlertServiceConfig().initialize(navigatorKey: navigatorKey);
runApp(MyApp(navigatorKey: navigatorKey));
}
class MyApp extends StatelessWidget {
final GlobalKey<NavigatorState> navigatorKey;
const MyApp({Key? key, required this.navigatorKey}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
// ... diğer konfigürasyonlar
);
}
}
AdminSidebar #
import 'package:pluggy/admin_sidebar/sidebar.dart';
import 'package:pluggy/admin_sidebar/sidebar_item.dart';
import 'package:provider/provider.dart';
class AdminPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => SidebarController(),
child: Row(
children: [
SidebarWidget(
items: [
SidebarItem(
title: "Dashboard",
route: "/dashboard",
icon: Icons.dashboard,
),
SidebarItem(
title: "Kullanıcılar",
route: "/users",
icon: Icons.people,
),
],
),
Expanded(
child: // Ana içerik
),
],
),
);
}
}
GoRouter Kurulumu #
Bu paket GoRouter kullanır. Ana uygulamanızda GoRouter kurulu olmalıdır:
dependencies:
go_router: ^13.0.0
provider: ^6.1.1
Sorun Giderme #
"No GoRouter found in context" Hatası #
Bu hata, uygulamanızda GoRouter kurulu olmadığında veya context'te bulunamadığında oluşur.
Çözüm 1: GoRouter kurun ve AlertService'i GoRouter context ile başlatın:
AlertServiceConfig().initialize(context: context);
Çözüm 2: Eski Navigator yöntemini kullanın:
AlertServiceConfig().initialize(navigatorKey: navigatorKey);
Context Parametresi #
AlertService metodlarında context parametresi kullanarak daha güvenli çalıştırabilirsiniz:
// Context ile (önerilen)
AlertService.showSnackBar("Mesaj", context: context);
// Context olmadan (fallback kullanır)
AlertService.showSnackBar("Mesaj");
SmartAlert #
SmartAlert, sağ altta yığılan, otomatik kaybolan ve maksimum 5 öğe gösteren bir uyarı/toast bileşenidir.
import 'package:pluggy/services/alert_service/smart_alert.dart';
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
SmartAlert.init(navigatorKey);
runApp(MaterialApp(
navigatorKey: navigatorKey,
home: const MyHomePage(),
));
}
// Gösterim örnekleri
void showAlerts() {
SmartAlert.show(AlertType.success, 'Başarılı', 'İşlem tamamlandı');
SmartAlert.show(AlertType.error, 'Hata', 'Bir şeyler ters gitti');
SmartAlert.show(AlertType.warning, 'Uyarı', 'Dikkat edilmesi gereken durum');
SmartAlert.show(AlertType.info, 'Bilgi', 'Bilgilendirme mesajı');
}
// Tüm uyarıları kapatmak için
void dismissAll() {
SmartAlert.dismissAll();
}
Lisans #
Bu proje MIT lisansı altında lisanslanmıştır.