ditwin_alert 0.0.2
ditwin_alert: ^0.0.2 copied to clipboard
A clean, customizable alert notification system for Flutter applications
đ ditwin_alert Documentation #
đ ditwin_alert is a Flutter package that provides customizable alert messages for input fields.
đ Installation #
1ī¸âŖ Add Dependency #
If your package is published on pub.dev, add this in pubspec.yaml:
dependencies:
ditwin_alert: latest_version # Replace with actual version
For local development, link it in pubspec.yaml:
dependencies:
ditwin_alert:
path: ../ditwin_alert # Adjust based on your project structure
Run:
flutter pub get
đ Usage #
1ī¸âŖ Import the Package #
import 'package:ditwin_alert/input_field_alert.dart';
2ī¸âŖ Basic Usage #
Use the InputFieldAlert inside your form:
InputFieldAlert(
message: "Field cannot be empty", // Alert message
alertType: AlertType.error, // Type of alert (success, error, warning, info)
)
3ī¸âŖ Full Example #
import 'package:flutter/material.dart';
import 'package:ditwin_alert/input_field_alert.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('DI-Twin Input Alert')),
body: const Padding(
padding: EdgeInsets.all(16.0),
child: InputForm(),
),
),
);
}
}
class InputForm extends StatefulWidget {
const InputForm({Key? key}) : super(key: key);
@override
_InputFormState createState() => _InputFormState();
}
class _InputFormState extends State<InputForm> {
final TextEditingController _controller = TextEditingController();
String? _errorMessage;
void _validateInput() {
setState(() {
if (_controller.text.isEmpty) {
_errorMessage = "Field cannot be empty";
} else if (_controller.text.length < 3) {
_errorMessage = "Input must be at least 3 characters";
} else {
_errorMessage = null;
}
});
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: _controller,
decoration: const InputDecoration(
labelText: "Enter text",
border: OutlineInputBorder(),
),
onChanged: (value) => _validateInput(),
),
const SizedBox(height: 8),
if (_errorMessage != null)
InputFieldAlert(
message: _errorMessage!,
alertType: AlertType.error,
width: 320,
height: 45,
borderRadius: 10,
fontSize: 14,
backgroundColor: Colors.black12,
textColor: Colors.red,
),
],
);
}
}
đ¨ Customization #
You can customize the alert appearance:
| Property | Type | Description | Default |
|---|---|---|---|
message |
String |
The text to display in the alert | Required |
alertType |
AlertType |
Type of alert (success, error, warning, info) |
Required |
width |
double? |
Width of the alert box | 300.0 |
height |
double? |
Height of the alert box | 50.0 |
borderRadius |
double? |
Rounded corners | 8.0 |
fontSize |
double? |
Font size of the message | 16.0 |
backgroundColor |
Color? |
Background color of the alert | Varies by type |
textColor |
Color? |
Text color | Colors.white |
đ¯ Alert Types #
Use AlertType to set different alert styles:
AlertType.success // â
Green alert
AlertType.error // â Red alert
AlertType.warning // â ī¸ Yellow alert
AlertType.info // âšī¸ Blue alert
Example:
InputFieldAlert(
message: "Your data has been saved!",
alertType: AlertType.success,
)
đ Running Tests #
To verify functionality, run:
flutter test
đ Roadmap & Future Enhancements #
âī¸ Auto-dismiss alert after a few seconds
âī¸ Fade-in/out animations
âī¸ Allow positioning (top/bottom/inline)
đ License #
This package is open-source under the MIT License.
đŠ Need Help? #
If you find issues or have feature requests, open an issue or pull request on GitHub.