sweetnotify 0.0.2
sweetnotify: ^0.0.2 copied to clipboard
SweetNotify is a Flutter package that allows you to show modern and customizable notifications in your applications.
import 'package:flutter/material.dart';
import 'package:sweetnotify/sweetnotify.dart';
void main() {
runApp(const MyApp());
}
/// Main widget demonstrating SweetNotify with separate buttons for each type
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SweetNotify Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.teal),
home: const NotificationPage(),
);
}
}
/// Page with three buttons, each triggering a different notification type
class NotificationPage extends StatelessWidget {
const NotificationPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SweetNotify Example'),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Success Button
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
backgroundColor: Colors.green,
),
icon: const Icon(Icons.check_circle, color: Colors.white),
label: const Text('Show Success', style: TextStyle(fontSize: 16)),
onPressed: () {
SweetNotify.show(
context,
title: 'Success',
subtitle: 'The operation was successful!',
type: SweetNotifyType.success,
);
},
),
const SizedBox(height: 20),
// Error Button
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
backgroundColor: Colors.red,
),
icon: const Icon(Icons.error, color: Colors.white),
label: const Text('Show Error', style: TextStyle(fontSize: 16)),
onPressed: () {
SweetNotify.show(
context,
title: 'Error',
subtitle: 'Something went wrong!',
type: SweetNotifyType.error,
);
},
),
const SizedBox(height: 20),
// Info Button
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
backgroundColor: Colors.blue,
),
icon: const Icon(Icons.info, color: Colors.white),
label: const Text('Show Info', style: TextStyle(fontSize: 16)),
onPressed: () {
SweetNotify.show(
context,
title: 'Info',
subtitle: 'This is an informational message.',
type: SweetNotifyType.info,
);
},
),
],
),
),
);
}
}