FlutterToastify
FlutterToastify, özelleştirilebilir toast benzeri mesajlarla kullanıcı bildirimleri göstermek için kullanılan bir Flutter paketidir. Bu paket, başarı, hata ve bilgi bildirimlerini isteğe bağlı ilerleme göstergeleri ve özel animasyonlarla göstermenizi sağlar.
Kullanım
- İlk olarak, projenize
flutter_toastifypaketini ekleyin.pubspec.yamldosyasını aşağıdaki gibi düzenleyin:
dependencies:
flutter:
sdk: flutter
flutter_toastify: ^1.0.0
-
Daha sonra, paketi projenize eklemek için
flutter pub getkomutunu çalıştırın. -
İşte bir örnek kod:
import 'package:flutter/material.dart';
import 'package:flutter_toastify/flutter_toastify.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FlutterToastify Demo'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
FlutterToastify.showToast(
title: 'Başarılı!',
description: 'Bu, bir başarı bildirimidir.',
type: FlutterToastifyType.success,
showProgressIndicator: true,
autoDismiss: true,
);
},
child: Text('Bildirim Göster'),
),
),
);
}
}
Bu örnekte, FlutterToastify.showToast fonksiyonu, başarı bildirimi göstermek için kullanılmıştır. Bildirimde ilerleme göstergesi ve otomatik kapanma özelliği bulunmaktadır.
Özellikler
FlutterToastifySınıfı:
class FlutterToastify {
FlutterToastify._(); // Özel yapılandırıcı
static void showToast({
String? title,
required String description,
FlutterToastifyType type = FlutterToastifyType.custom,
bool showProgressIndicator = true,
Duration duration = const Duration(milliseconds: 3000),
bool autoDismiss = true,
Function()? onCloseButtonPressed,
}) {
// Verilen yapılandırmalarla bildirim gösterilir.
}
}
title: Bildirim başlığı. Varsayılan olaraknullve görüntülenmez.description: Bildirim açıklama metni (zorunlu).type: Bildirim tipi (FlutterToastifyTypeenumundan). Varsayılan değerFlutterToastifyType.custom.showProgressIndicator: Bildirimde ilerleme göstergesi gösterilsin mi? Varsayılan değertrue.duration: Bildirimin gösterileceği süre. Varsayılan değerDuration(milliseconds: 3000)(3 saniye).autoDismiss: Bildirimin belirtilen süre sonra otomatik olarak kapanıp kapanmayacağını belirtir. Varsayılan değertrue.onCloseButtonPressed: Bildirimin kapatma düğmesine basıldığında çağrılacak geri çağırma fonksiyonu.
Stil
FlutterToastifyStyle sınıfı, özel renkler ve stiller için statik özellikler sağlar:
class FlutterToastifyStyle {
static Color get successColor => Color(0xff01CB67);
static Color get errorColor => Color(0xffFE355C);
static Color get infoColor => Color(0xff0066FF);
static Color get defaultColor => Colors.blue;
static EdgeInsetsGeometry get contentPadding =>
EdgeInsets.symmetric(horizontal: 24, vertical: 20);
static double get iconSize => 20.0;
}
Lisans
Bu proje MIT Lisansı altında lisanslanmıştır. Daha fazla bilgi için LICENSE dosyasını inceleyebilirsiniz.
FlutterToastify
FlutterToastify is a Flutter package used to display user notifications with customizable toast-like messages. This package provides an easy way to show success, error, and info notifications with optional progress indicators and custom animation.
Usage
- First, add the
flutter_toastifypackage to your project. Edit thepubspec.yamlfile as follows:
dependencies:
flutter:
sdk: flutter
flutter_toastify: ^1.0.0
-
Next, run
flutter pub getto fetch the package. -
Here's an example code:
import 'package:flutter/material.dart';
import 'package:flutter_toastify/flutter_toastify.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FlutterToastify Demo'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
FlutterToastify.showToast(
title: 'Success!',
description: 'This is a success notification.',
type: FlutterToastifyType.success,
showProgressIndicator: true,
autoDismiss: true,
);
},
child: Text('Show Notification'),
),
),
);
}
}
In this example, FlutterToastify.showToast function is used to show a success notification with a progress indicator and auto-dismiss feature.
Features
FlutterToastifyClass:
class FlutterToastify {
FlutterToastify._(); // Private constructor
static void showToast({
String? title,
required String description,
FlutterToastifyType type = FlutterToastifyType.custom,
bool showProgressIndicator = true,
Duration duration = const Duration(milliseconds: 3000),
bool autoDismiss = true,
Function()? onCloseButtonPressed,
}) {
// Show notification with provided configurations.
}
}
title: The title of the notification. By default, it'snulland won't be displayed.description: The description text of the notification (required).type: The type of notification (fromFlutterToastifyTypeenum). The default value isFlutterToastifyType.custom.showProgressIndicator: Specifies whether to show a progress indicator in the notification. The default value istrue.duration: The duration for which the notification will be displayed. The default value isDuration(milliseconds: 3000)(3 seconds).autoDismiss: Specifies whether the notification will automatically dismiss after the specified duration. The default value istrue.onCloseButtonPressed: A callback function that will be called when the notification's close button is pressed.
Styling
The FlutterToastifyStyle class provides static properties for custom colors and styles:
class FlutterToastifyStyle {
static Color get successColor => Color(0xff01CB67);
static Color get errorColor => Color(0xffFE355C);
static Color get infoColor => Color(0xff0066FF);
static Color get defaultColor => Colors.blue;
static EdgeInsetsGeometry get contentPadding =>
EdgeInsets.symmetric(horizontal: 24, vertical: 20);
static double get iconSize => 20.0;
}
License
This project is licensed under the MIT License. For more information, see the LICENSE file.