Custom Package

A flexible Flutter package for performing arithmetic operations with a clean, reactive UI using the GetX state management library. It provides a simple pub/sub mechanism to broadcast results and a ready-to-use view for user interaction.

Features

  • Arithmetic Operations: Core functions for addition, subtraction, multiplication, and division.
  • Reactive State Management: Built with GetX for efficient and low-overhead state management.
  • Pub/Sub Pattern: A CustomPublisher class that broadcasts messages, making it easy to listen for changes from anywhere in your app.
  • Ready-to-Use UI: A pre-built CustomPackageView widget with text fields for input and buttons for all arithmetic operations.
  • Attractive Animations: Smooth button press animations, fade-in results, and visual feedback for better UX.
  • Modern Design: Clean, card-based layout with shadows, rounded corners, and a contemporary color scheme.
  • Error Handling: Gracefully handles common errors like division by zero with color-coded feedback.
  • Customizable & Extendable: Easily extend the existing classes to add more functionality.

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  custom_package: ^0.0.1

Then, run flutter pub get in your terminal.

Usage

Here’s a simple example of how to use the CustomPackageView in your app:

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:custom_package/simple_package.dart';

void main() {
  runApp(const MyExampleApp());
}

class MyExampleApp extends StatelessWidget {
  const MyExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Custom Pub Package Demo',
      home: CustomPackageView(),
    );
  }
}

Listening to Changes

You can also listen to the stream of messages from the CustomPublisher manually:

final CustomPublisher controller = Get.find();

controller.stream.listen((message) {
  if (message != null) {
    print(message.message); // Outputs the result of the arithmetic operation
  }
});

API Documentation

CustomPublisher

The main controller class that handles arithmetic operations and broadcasts results.

Methods

  • void add(int a, int b) - Performs addition and publishes the result
  • void subtract(int a, int b) - Performs subtraction and publishes the result
  • void multiply(int a, int b) - Performs multiplication and publishes the result
  • void divide(int a, int b) - Performs division with zero-division error handling
  • void publish(String text) - Manually publish a custom message

Properties

  • CustomMessage? latest - Get the latest published message
  • Stream<CustomMessage?> stream - Stream of messages for listening to changes

CustomMessage

A simple data model that wraps the result message.

class CustomMessage {
  final String message;
  CustomMessage(this.message);
}

CustomPackageView

A complete UI widget that provides:

  • Two text input fields for entering numbers
  • Four operation buttons (Add, Subtract, Multiply, Divide)
  • Real-time display of results
  • Automatic input validation and error handling

Example Project

Check out the /example folder in this repository for a complete working example of how to integrate this package into your Flutter app.

Requirements

  • Flutter SDK: >=1.17.0
  • Dart SDK: ^3.5.4
  • GetX: ^4.7.2

Version History

0.0.1

  • Initial release
  • Basic arithmetic operations (add, subtract, multiply, divide)
  • GetX-based state management
  • Ready-to-use UI components
  • Pub/sub pattern implementation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! If you have suggestions or find a bug, please feel free to open an issue or submit a pull request on our GitHub repository.

Development Setup

  1. Clone the repository
  2. Run flutter pub get
  3. Run tests with flutter test
  4. Run the example with flutter run example/main.dart

Support

If you like this package, consider giving it a ⭐ on GitHub!