sync_ease 0.0.9 copy "sync_ease: ^0.0.9" to clipboard
sync_ease: ^0.0.9 copied to clipboard

A lightweight Flutter State Management library for simplified state handling in Flutter applications.

SyncEase #

enter image description here SyncEase is a lightweight and versatile state management library for Flutter applications. It provides simple yet powerful tools for managing the state of your application with ease.

Features #

  • Simple API: SyncEase offers a straightforward API for managing state, making it easy to integrate into your Flutter projects.
  • Error Handling: Easily handle errors within your application state and propagate them to your UI.
  • Loading State: Manage loading states within your application, providing feedback to users during asynchronous operations.
  • Batch Operations: Perform batch operations on your state, allowing you to update multiple values atomically.
  • Listener Support: SyncEase supports listeners, allowing you to react to state changes and update your UI accordingly.
  • Versatile: Suitable for various types of state management scenarios, including simple value states and list states.
  • App Simulator: SyncEase provides methods for simulating various gestures and keyboard inputs in Flutter applications. This is particularly useful for testing UI interactions and automating certain user actions.
  • EaseDevice Utility: The EaseDevice class provides various utilities for accessing device-related information and functionalities in Flutter applications. These utilities include checking internet connectivity, retrieving screen dimensions, determining the platform name and version, setting screen orientation, managing full-screen mode, detecting device type (mobile, tablet, desktop), handling the software keyboard, and more.

Installation #

To use SyncEase in your Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:  
sync_ease: ^1.0.0`  
  

Then, run flutter pub get to install the package.

Usage #

Here's a simple example of how to use SyncEase to manage state in your Flutter application:

1. Import SyncEase #

import 'package:sync_ease/sync_ease.dart';  
  

2. Create an Instance of Ease #

final Ease<int> counter = Ease(0);  
  

3. Use EaseBuilder to React to State Changes #

EaseBuilder<int>(  
ease: counter,  
builder: (context, value) => Text(  
value.toString(),  
style: TextStyle(fontSize: 24),  
),  
),  
  

4. Update State Values #

counter.value++; // Increment the counter  

Counter App With SyncEase #

import 'package:flutter/material.dart';  
import 'package:sync_ease/sync_ease.dart';  
  
class CounterLogic extends SyncEaseLogic{  
int a=0;  
  
increment(){  
a++;  
put(); // update Logic Builder Widget  
}  
}  
  
class MyApp extends StatelessWidget{  
final CounterLogic _counterLogic=SyncEaseLogic.reg(CounterLogic());  
  
MyApp({super.key});  
@override  
Widget build(BuildContext context) {  
return Scaffold(  
floatingActionButton: FloatingActionButton(  
child: const Icon(Icons.add),  
onPressed: (){  
_counterLogic.increment();  
},  
),  
body: Center(  
child: LogicBuilder(  
logic: _counterLogic,  
builder: (BuildContext context) {  
return Text(_counterLogic.a.toString());  
},  
)  
),  
);  
}  
  
}  
  

Advantages #

  • Simplicity: SyncEase offers a simple and intuitive API, making it easy to manage state in Flutter applications.
  • Flexibility: It provides various features like error handling, loading state management, and batch operations, catering to diverse state management needs.
  • Efficiency: With its listener support and batch operations, SyncEase ensures efficient state updates and UI rendering.
  • Compatibility: SyncEase seamlessly integrates with existing Flutter projects and other state management solutions, allowing for smooth adoption.
  • Show Snack Bar, Alert Dialog, and Date Picker Anywhere in the App

Dialogs #

Show Snack Bar, Alert Dialog, and Date Picker Anywhere in the App #

You can now use the showSyncSnackBar, showSyncAlertBox, and showSyncDatePicker functions to display snack bars, alert dialogs, and date pickers from anywhere in the app, even outside the widget tree.

Example

showSyncSnackBar(SnackBar(content: Text('Hello, world!')));  
  
showSyncAlertBox(  
builder: (BuildContext context) => AlertDialog(  
title: Text('Alert'),  
content: Text('This is an alert dialog.'),  
),  
);  
  
showSyncDatePicker(  
initialDate: DateTime.now(),  
firstDate: DateTime(2022),  
lastDate: DateTime(2025),  
);  
  

Simple Navigation #

to(SecondPage());  
to(SecondPage(),asrguments:{"name":"Jhone"});  
back();  

EaseSimulator Class #

The EaseSimulator class provides methods for simulating various gestures and keyboard inputs in Flutter applications. This class is particularly useful for testing UI interactions and automating certain user actions.

Methods #

  • getWidgetOffset(GlobalKey key): Offset?

  • Retrieves the offset of a widget identified by its GlobalKey on the screen.

  • tapDown(Offset offset, {bool showGestureMarker = true}): Future

  • Simulates a tap down event at the specified position on the screen.

  • tapUp(Offset offset, {bool showGestureMarker = true}): Future

  • Simulates a tap up event at the specified position on the screen.

  • tap(Offset offset, {bool showGestureMarker = true}): Future

  • Simulates a tap event (tap down followed by tap up) at the specified position on the screen.

  • longPress(Offset offset, {bool showGestureMarker = true}): Future

  • Simulates a long press event at the specified position on the screen.

  • scroll(Offset startOffset, Offset endOffset): Future

  • Simulates a scroll gesture starting from the given start offset to the end offset.

  • insertText(String text): Future

  • Inserts text into a text input field, simulating user keyboard input.

  • pinch(Offset focalPoint1, Offset focalPoint2): Future

  • Simulates a pinch gesture between two focal points on the screen.

  • zoom(Offset focalPoint1, Offset focalPoint2): Future

  • Simulates a zoom gesture between two focal points on the screen.

  • showGestureIndicator({required Offset position, Color color = Colors.red}): void

  • Displays a visual indicator at the specified position on the screen, useful for debugging and visualization of gestures.

Example Usage for getWidgetOffset #

Offset? offset = EaseSimulator.getWidgetOffset(GlobalKey());  
if (offset != null) {  
print("Widget Offset: $offset");  
}  

Example Usage for tapDown #

Offset offset = Offset(offset);  
await EaseSimulator.tapDown(offset);  

Example Usage for tapUp #

Offset offset = Offset(100, 200);  
await EaseSimulator.tapUp(offset);  

Example Usage for tap #

Offset offset = Offset(100, 200);  
await EaseSimulator.tap(offset);  

Example Usage for longPress #

Offset offset = Offset(100, 200);  
await EaseSimulator.longPress(offset);  

Example Usage for scroll #

Offset startOffset = Offset(100, 200);  
Offset endOffset = Offset(100, 300);  
await EaseSimulator.scroll(startOffset, endOffset);  

Example Usage for insertText #

await EaseSimulator.insertText("Hello, World!");  

Example Usage for pinch #

Offset focalPoint1 = Offset(100, 200);  
Offset focalPoint2 = Offset(200, 300);  
await EaseSimulator.pinch(focalPoint1, focalPoint2);  

Example Usage for zoom #

Offset focalPoint1 = Offset(100, 200);  
Offset focalPoint2 = Offset(200, 300);  
await EaseSimulator.zoom(focalPoint1, focalPoint2);  

Example Usage for showGestureIndicator #

Offset position = Offset(100, 200);  
EaseSimulator.showGestureIndicator(position: position, color: Colors.blue); 

EaseDevice Utility Class #

The EaseDevice class provides various utilities for accessing device-related information and functionalities in Flutter applications. These utilities include checking internet connectivity, retrieving screen dimensions, determining the platform name and version, setting screen orientation, managing full-screen mode, detecting device type (mobile, tablet, desktop), handling the software keyboard, and more.

Methods #

  • isOnline(): Future

    • Checks if the device is connected to the internet.
  • getScreenSize(): Size

    • Retrieves the screen dimensions.
  • getScreenWidth(): double

    • Retrieves the screen width.
  • getScreenHeight(): double

    • Retrieves the screen height.
  • getPixelDensity(): double

    • Retrieves the pixel density or device pixel ratio.
  • getPlatformName(): String

    • Retrieves the platform name (e.g., "Android", "iOS").
  • getPlatformVersion(): String

    • Retrieves the platform version.
  • isTablet(): bool

    • Checks if the device is a tablet.
  • fullScreen(): Future

    • Sets the app to full-screen mode.
  • setOrientation(DeviceOrientation orientation): Future

    • Sets the preferred orientation for the app.
  • exitFullScreen(): void

    • Exits full-screen mode.
  • isMobile(): bool

    • Checks if the device is a mobile phone.
  • isDesktop(): bool

    • Checks if the device is a desktop/laptop.
  • getPlatformLocale(): String

    • Retrieves the platform's locale.
  • hasPhysicalKeyboard(): bool

    • Checks if the device has a physical keyboard.
  • openKeyboard(): void

    • Opens the software keyboard.
  • hideKeyboard(): void

    • Hides the software keyboard.

Example Usage #

import 'package:your_package/ease_device.dart';

void main() async {
  // Check internet connectivity
  bool isOnline = await EaseDevice.isOnline();
  print('Is Online: $isOnline');

  // Retrieve screen size
  Size screenSize = EaseDevice.getScreenSize();
  print('Screen Size: $screenSize');

  // Check device type
  bool isMobile = EaseDevice.isMobile();
  bool isTablet = EaseDevice.isTablet();
  bool isDesktop = EaseDevice.isDesktop();
  print('Is Mobile: $isMobile, Is Tablet: $isTablet, Is Desktop: $isDesktop');

  // Set full-screen mode
  await EaseDevice.fullScreen();

  // Hide keyboard
  EaseDevice.hideKeyboard();
}

Documentation #

For detailed documentation and API reference, visit the SyncEase Documentation.

Contributing #

Contributions to SyncEase are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request on GitHub.

12
likes
0
points
31
downloads

Publisher

verified publishermypackeges.tk

Weekly Downloads

A lightweight Flutter State Management library for simplified state handling in Flutter applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on sync_ease