extensionresoft 0.0.6 copy "extensionresoft: ^0.0.6" to clipboard
extensionresoft: ^0.0.6 copied to clipboard

A collection of Dart/Flutter Extension functions and Helper functions for faster development. It absolutely makes for codes re-usability and easy coding reading.

extensionresoft #

pub package pub points popularity likes Star on Github Awesome Flutter License: BSD

A collection of useful Dart/Flutter Extension functions and Helper functions for faster development. This was developed to aide developers write minimized but powerful codes. This makes for codes re-usability and easy coding reading. It's aimed at enhancing productivity and improving code readability.

Table of Contents #

Installation #

To use the extensionresoft library in your Flutter project, add it to your pubspec.yaml file:

dependencies:
  extensionresoft: ^0.0.6

Then, run:

flutter pub get

to install the dependencies.

Usage #

Import the extensionresoft library in your Dart files:

import 'package:extensionresoft/extensionresoft.dart';

You can now use any of the extensions provided by the library in your Flutter project.

Features #

The extensionresoft library includes the following major extensions among others:

  • SpaceExtension: Provides methods for creating SizedBox widgets with customizable dimensions.
  • CustomCardExtension: Offers methods for creating custom Card widgets with rounded corners and other properties.
  • PathExtension: Provides a method for applying functions to numbers.
  • TextExtension: Offers a method for creating Text widgets with customizable properties from strings.
  • CustomImageExtension: Provides methods for creating Image widgets and circular image containers with customizable properties.
  • Conditional Function: Provides functions for conditionally returning values.
  • Get Function: Provides a function for getting values with optional default values.
  • SharedPreferencesService: Manages SharedPreferences for storing and retrieving various data types.

Examples #

Check out the Examples section below for code examples demonstrating how to use the extensions provided by the extensionresoft library.

import 'package:extensionresoft/extensionresoft.dart';
import 'package:flutter/material.dart';

void main() {
  // SpaceExtension Example
  final spacerX = 16.spaceX(); // Creates a SizedBox with a width of 16.
  final spacerY = 24.spaceY(); // Creates a SizedBox with a height of 24.
  final spacerXY = 32.spaceXY(); // Creates a SizedBox with both width and height of 32.
  final spacerXGetter = 20.spX; // Getter example: Creates a SizedBox with a width of 20.
  final spacerYGetter = 30.spY; // Getter example: Creates a SizedBox with a height of 30.
  final spacerXYGetter = 40.spXY; // Getter example: Creates a SizedBox with both width and height of 40.

  // CustomCardExtension Example
  final roundedCard = 16.radius(
    child: const Text('Hello World'),
    elevation: 4,
    color: Colors.blue,
    strokeColor: Colors.black,
    shadowColor: Colors.grey,
  ); // Creates a rounded card with specified properties.

  // PathExtension Example
  final result = 16.p((n) => n * 2); // Applies a function to the number 16 and returns the result.

  // TextExtension Example
  final textWidget = 'Hello'.edit(textStyle: const TextStyle(fontSize: 20), textAlign: TextAlign.center); // Creates a customized Text widget.

  // CustomImageExtension Example
  final imageWidget = 'assets/image.png'.img(width: 100, height: 100, fit: BoxFit.cover); // Creates an Image widget from an asset with specified properties.
  final circleImageContainer = 'assets/avatar.png'.circleImage(fit: BoxFit.cover, opacity: 0.8); // Creates a circular image container with specified properties.

  // Conditional Function Example
  final conditionResult = condition(true, 'True Value', 'False Value'); // Returns 'True Value' based on the condition.
  final conditionFunctionResult = conditionFunction(true, () => 'True Value', () => 'False Value'); // Invokes a function based on the condition.

  // Get Function Example
  final value = get('Existing Value', 'Default Value'); // Returns 'Existing Value' if not null, otherwise returns 'Default Value'.

  // SharedPreferencesService Example
  await SharedPreferencesService.init(); // Initializes SharedPreferencesService.
  await SharedPreferencesService.setBool('isDarkMode', true); // Sets a boolean value in SharedPreferences.
  final isDarkMode = SharedPreferencesService.getBool('isDarkMode'); // Retrieves the boolean value from SharedPreferences.
}

Tests #

Check out unit tests for the extensionresoft library to ensure the functionality of each extension.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:extensionresoft/extensionresoft.dart';

void main() {
  group('SpaceExtension', () {
    test('spaceX should return a SizedBox with specified width', () {
      final spacerX = 16.spaceX();
      expect(spacerX.width, equals(16.0));
    });

    test('spaceY should return a SizedBox with specified height', () {
      final spacerY = 24.spaceY();
      expect(spacerY.height, equals(24.0));
    });

    test('spaceXY should return a SizedBox with specified width and height', () {
      final spacerXY = 32.spaceXY();
      expect(spacerXY.width, equals(32.0));
      expect(spacerXY.height, equals(32.0));
    });

    test('spX getter should return a SizedBox with specified width', () {
      final spacerXGetter = 20.spX;
      expect(spacerXGetter.width, equals(20.0));
    });

    test('spY getter should return a SizedBox with specified height', () {
      final spacerYGetter = 30.spY;
      expect(spacerYGetter.height, equals(30.0));
    });

    test('spXY getter should return a SizedBox with specified width and height', () {
      final spacerXYGetter = 40.spXY;
      expect(spacerXYGetter.width, equals(40.0));
      expect(spacerXYGetter.height, equals(40.0));
    });
  });

  group('CustomCardExtension', () {
    test('radius should return a Card widget with specified properties', () {
      final Card roundedCard = 16.radius(
        child: const Text('Test'),
        elevation: 4,
        color: Colors.blue,
        strokeColor: Colors.black,
        shadowColor: Colors.grey,
      ) as Card;

      expect(roundedCard.elevation, equals(4));
      expect(roundedCard.color, equals(Colors.blue));
      expect(roundedCard.shadowColor, equals(Colors.grey));
    });
  });

  group('PathExtension', () {
    test('p function should apply function to number and return result', () {
      final result = 16.p((n) => n * 2);
      expect(result, equals(32.0));
    });
  });

  group('TextExtension', () {
    test('edit function should return a Text widget with specified properties', () {
      final textWidget = 'Hello'.edit(textStyle: const TextStyle(fontSize: 20), textAlign: TextAlign.center);
      expect(textWidget.data, equals('Hello'));
      expect(textWidget.style!.fontSize, equals(20));
      expect(textWidget.textAlign, equals(TextAlign.center));
    });
  });

  group('CustomImageExtension', () {
    test('img function should return an Image widget with specified properties', () {
      final imageWidget = 'assets/image.png'.img(width: 100, height: 100, fit: BoxFit.cover);
      expect(imageWidget.width, equals(100.0));
      expect(imageWidget.height, equals(100.0));
    });

    test('circleImage function should return a Container widget with circular image decoration', () {
      final circleImageContainer = 'assets/avatar.png'.circleImage(fit: BoxFit.cover, opacity: 0.8);
      //expect(circleImageContainer.decoration!.shape, equals(BoxShape.circle));
    });
  });

  group('Conditional Function', () {
    test('condition function should return correct value based on condition', () {
      final result = condition(true, 'True Value', 'False Value');
      expect(result, equals('True Value'));
    });

    test('conditionFunction should invoke correct function based on condition', () {
      final result = conditionFunction(true, () => 'True Value', () => 'False Value');
      expect(result, equals('True Value'));
    });
  });

  group('Get Function', () {
    test('get function should return correct value based on key and default value', () {
      final result = get('Existing Value', 'Default Value');
      expect(result, equals('Existing Value'));
    });
  });
}

Screenshots #

(None applicable in this current release)

Contributing #

Contributions to the extensionresoft library are welcome! If you have any ideas for new extensions or improvements to existing ones, please open an issue or submit a pull request on GitHub.

License #

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

4
likes
160
pub points
63%
popularity

Publisher

unverified uploader

A collection of Dart/Flutter Extension functions and Helper functions for faster development. It absolutely makes for codes re-usability and easy coding reading.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on extensionresoft