📖 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.