Overview

The TBDC Flutter Plugin is a versatile collection of utilities for Flutter applications, featuring various helper classes and UI components to enhance development. This document focuses on the Helpers section and UI Components section.

Table of Contents

Installation

To integrate the TBDC Flutter Plugin into your Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:
  tbdc_flutter_plugin: ^1.2.0

And run:

flutter pub get

Helpers

CompareListsOfObject

The CompareListsOfObject class provides functionality to compare lists of objects based on a specified field ID. It returns a CompareListsOfObjectsResult object containing lists of added, removed, and updated items.

CompareListsOfObjectResult<MyObject> result = CompareListsOfObject
	.compare(
		oldList: oldList,
		newList: newList,
		fieldId: 'uniqueField',
	);

Usage

Ensure that the objects in your lists implement the ObjectComparable interface. This interface mandates the implementation of the map getter, returning a map representing the object.

class MyObject implements ObjectComparable {
	// ... other properties and methods ...

	@override
	Map<String, dynamic> get map {
	    return {
		    'field1': field1,
		    'field2': field2,
		    // ... other fields ...
    };
  }
}

The class provides two methods for comparison:

  1. Synchronous comparison:
CompareListsOfObjectResult<MyObject> result = CompareListsOfObject.compare(
  oldList: oldList,
  newList: newList,
  fieldId: 'uniqueField',
);
  1. Asynchronous comparison (recommended for large lists):
CompareListsOfObjectResult<MyObject> result = await CompareListsOfObject.compareAsync(
  oldList: oldList,
  newList: newList,
  fieldId: 'uniqueField',
);

Example

// Import the TBDC Flutter Plugin
import 'package:tbdc_flutter_plugin/tbdc_flutter_plugin.dart';

// Define your custom class implementing ObjectComparable
class MyObject implements ObjectComparable {
  final String id;
  final String name;

  MyObject({required this.id, required this.name});

  @override
  Map<String, dynamic> get map => {
    'id': id,
    'name': name,
  };
}

// Create lists of your objects
List<MyObject> oldList = [...];
List<MyObject> newList = [...];

// Compare lists synchronously
CompareListsOfObjectResult<MyObject> syncResult = CompareListsOfObject.compare(
  oldList: oldList,
  newList: newList,
  fieldId: 'uniqueField',
);

// Or compare asynchronously (recommended for large lists)
CompareListsOfObjectResult<MyObject> asyncResult = await CompareListsOfObject.compareAsync(
  oldList: oldList,
  newList: newList,
  fieldId: 'id',
);

// Access the results
print('Added items: ${result.added}');
print('Removed items: ${result.removed}');
print('Updated items: ${result.updated}');

UI Components

TBDCPhoneInput

A customizable phone input widget that supports international phone numbers with country selection and automatic formatting.

Usage

The widget provides the following features:

  • Country selection with flag display
  • Automatic phone number formatting
  • Input validation
  • Localization support
  • Customizable styling
TBDCPhoneInput(
  initialValue: '+55 (11) 91234-5678',
  title: 'Phone Number',
  onChanged: (value, isValid) {
    // Handle phone number changes
  },
);

Example

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

class MyPhoneInputScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: TBDCPhoneInput(
          title: 'Contact Number',
          initialValue: '+1 (555) 123-4567',
          onChanged: (phoneNumber, isValid) {
            if (isValid) {
              print('Valid phone number: $phoneNumber');
            }
          },
        ),
      ),
    );
  }
}

The phone input component will:

  • Display a country selector with flags
  • Format the phone number according to the selected country
  • Validate the input based on country-specific rules
  • Provide feedback about the validity of the number
  • Support internationalization