taskgate_sdk 1.0.7 copy "taskgate_sdk: ^1.0.7" to clipboard
taskgate_sdk: ^1.0.7 copied to clipboard

TaskGate SDK for Flutter - integrate with TaskGate to receive task requests and report completion.

TaskGate SDK for Flutter #

pub package

TaskGate SDK allows Flutter apps to integrate with TaskGate to receive task requests and report task completion status.

Features #

  • 🚀 Simple Dart API
  • 📱 iOS and Android support
  • ⚡ Stream-based task delivery
  • 🔄 Handles cold start and warm start scenarios
  • ⏰ Automatic lifecycle management

Installation #

Add this to your pubspec.yaml:

dependencies:
  taskgate_sdk: ^1.0.0

Then run:

flutter pub get

Platform Setup #

iOS #

1. Add TaskGateSDK dependency

The SDK is automatically included via CocoaPods. Make sure your ios/Podfile has:

platform :ios, '13.0'

Add your associated domain in Xcode:

  1. Open ios/Runner.xcworkspace
  2. Select your target → Signing & Capabilities
  3. Add "Associated Domains" capability
  4. Add applinks:yourdomain.com

Create an .well-known/apple-app-site-association file on your server:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appIDs": ["TEAM_ID.your.bundle.id"],
        "paths": ["/taskgate/*"]
      }
    ]
  }
}

Android #

1. Add TaskGate SDK to your app's build.gradle

The SDK is automatically included. Ensure your android/app/build.gradle has:

android {
    defaultConfig {
        minSdkVersion 21
    }
}

Add to your AndroidManifest.xml:

<activity android:name=".MainActivity">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="https"
            android:host="yourdomain.com"
            android:pathPrefix="/taskgate" />
    </intent-filter>
</activity>

Create an .well-known/assetlinks.json file on your server:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "your.package.name",
      "sha256_cert_fingerprints": ["YOUR_SHA256_FINGERPRINT"]
    }
  }
]

Usage #

Initialize the SDK #

Initialize early in your app's lifecycle:

import 'package:taskgate_sdk/taskgate_sdk.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize with your provider ID
  await TaskGateSdk.initialize(providerId: 'your_provider_id');

  runApp(MyApp());
}

Listen for Tasks #

Use the stream to receive task notifications:

class _MyAppState extends State<MyApp> {
  StreamSubscription<TaskInfo>? _taskSubscription;

  @override
  void initState() {
    super.initState();

    // Listen for incoming tasks
    _taskSubscription = TaskGateSdk.taskStream.listen((task) {
      print('Received task: ${task.taskId}');
      _navigateToTask(task);
    });

    // Check for pending task on cold start
    _checkPendingTask();
  }

  Future<void> _checkPendingTask() async {
    final task = await TaskGateSdk.getPendingTask();
    if (task != null) {
      _navigateToTask(task);
    }
  }

  void _navigateToTask(TaskInfo task) {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (_) => TaskScreen(task: task),
      ),
    );
  }

  @override
  void dispose() {
    _taskSubscription?.cancel();
    super.dispose();
  }
}

Report Completion #

When the user completes a task:

// User completed task and wants to open the blocked app
await TaskGateSdk.reportCompletion(CompletionStatus.open);

// User completed task but wants to stay focused
await TaskGateSdk.reportCompletion(CompletionStatus.focus);

// User cancelled the task
await TaskGateSdk.reportCompletion(CompletionStatus.cancelled);
// or use the convenience method:
await TaskGateSdk.cancelTask();

API Reference #

TaskGateSdk #

Method Description
initialize(providerId) Initialize the SDK with your provider ID
taskStream Stream of incoming task requests
getPendingTask() Get pending task (for cold start)
reportCompletion(status) Report task completion
cancelTask() Cancel the current task
hasActiveSession() Check if a task session is active
currentTask Get the current cached task
dispose() Clean up SDK resources

TaskInfo #

Property Type Description
taskId String Unique task identifier
sessionId String Session identifier
callbackUrl String URL to return to TaskGate
appName String? Name of blocked app
additionalParams Map<String, String> Additional parameters

CompletionStatus #

Value Description
open User completed task, open blocked app
focus User completed task, stay focused
cancelled User cancelled the task

Example #

See the example directory for a complete sample app.

Becoming a Partner #

Visit taskgate.co to learn more about partnership opportunities.

Contact us to register and get your providerId.


Support #


License #

MIT License - See LICENSE file for details.


Made with ❤️ for TaskGate Partners

1
likes
160
points
0
downloads

Publisher

verified publishertaskgate.co

Weekly Downloads

TaskGate SDK for Flutter - integrate with TaskGate to receive task requests and report completion.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on taskgate_sdk

Packages that implement taskgate_sdk