Skip to content

Installation & Setup

This guide will help you install and set up LDK (Lazy Development Kit) in your Flutter project.

Prerequisites

Before installing LDK, ensure you have:

  • Flutter SDK: Version 3.0.0 or higher
  • Dart SDK: Version 2.17.0 or higher
  • Strapi Backend: Version 4.0.0 or higher (recommended)

Installation

1. Add LDK to your project

Add LDK to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  ldk: ^2.0.0

2. Install dependencies

Run the following command to install the package:

flutter pub get

3. Import LDK

Import LDK in your Dart files:

import 'package:ldk/ldk.dart';

Platform-Specific Setup

Android Setup

1. Minimum SDK Version

Ensure your android/app/build.gradle has a minimum SDK version of 21:

android {
    compileSdkVersion 33

    defaultConfig {
        minSdkVersion 21  // Required for LDK
        targetSdkVersion 33
    }
}

2. Internet Permission

Add internet permission to android/app/src/main/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- For biometric authentication (optional) -->
    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />

    <application>
        <!-- Your app configuration -->
    </application>
</manifest>

3. ProGuard Configuration (Release builds)

If you're using ProGuard, add these rules to android/app/proguard-rules.pro:

# LDK specific rules
-keep class com.example.ldk.** { *; }
-keepclassmembers class * {
    @com.fasterxml.jackson.annotation.* *;
}

# Hive database rules
-keep class hive.** { *; }
-keep class **$HiveFieldAdapter { *; }

iOS Setup

1. Minimum iOS Version

Update your ios/Podfile to set the minimum iOS version:

platform :ios, '11.0'  # Required for LDK

2. Info.plist Configuration

Add network and biometric permissions to ios/Runner/Info.plist:

<dict>
    <!-- Network access -->
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

    <!-- Biometric authentication (optional) -->
    <key>NSFaceIDUsageDescription</key>
    <string>This app uses Face ID for secure authentication</string>

    <!-- Background processing for offline sync -->
    <key>UIBackgroundModes</key>
    <array>
        <string>background-processing</string>
        <string>background-fetch</string>
    </array>
</dict>

Web Setup

1. CORS Configuration

Ensure your Strapi server allows CORS for your web domain. In your Strapi project, update config/middlewares.js:

module.exports = [
  'strapi::errors',
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:', 'wss:'],
        },
      },
    },
  },
  {
    name: 'strapi::cors',
    config: {
      enabled: true,
      headers: '*',
      origin: ['http://localhost:3000', 'https://yourdomain.com'],
    },
  },
  // ... other middlewares
];

2. Web-Specific Features

Some features have limitations on web: - Biometric Authentication: Not available - Background Sync: Limited to service workers - File System Access: Uses browser storage APIs

Strapi Backend Setup

1. Required Strapi Plugins

Install these Strapi plugins for full LDK compatibility:

# GraphQL support
npm install @strapi/plugin-graphql

# User permissions
npm install @strapi/plugin-users-permissions

# Upload for file management
npm install @strapi/plugin-upload

2. Enable Plugins

Add plugins to your Strapi config/plugins.js:

module.exports = {
  'users-permissions': {
    enabled: true,
  },
  'upload': {
    enabled: true,
  },
  'graphql': {
    enabled: true,
    config: {
      endpoint: '/graphql',
      shadowCRUD: true,
      playgroundAlways: false,
      depthLimit: 7,
      amountLimit: 100,
      apolloServer: {
        tracing: false,
      },
    },
  },
};

3. Content Types

Create your content types in Strapi admin panel or using the CLI. LDK works with any Strapi content type.

Example content type (api/post/content-types/post/schema.json):

{
  "kind": "collectionType",
  "collectionName": "posts",
  "info": {
    "singularName": "post",
    "pluralName": "posts",
    "displayName": "Post"
  },
  "options": {
    "draftAndPublish": true
  },
  "attributes": {
    "title": {
      "type": "string",
      "required": true
    },
    "content": {
      "type": "richtext"
    },
    "author": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "plugin::users-permissions.user"
    },
    "tags": {
      "type": "json"
    },
    "publishedAt": {
      "type": "datetime"
    }
  }
}

Verification

Create a simple test to verify your installation:

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

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

  try {
    await LDK.initialize(
      baseUrl: 'https://your-strapi-server.com',
      enableLogging: true,
    );

    print('✅ LDK initialized successfully!');
    runApp(MyApp());
  } catch (e) {
    print('❌ LDK initialization failed: $e');
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'LDK Test App',
      home: Scaffold(
        appBar: AppBar(title: Text('LDK Test')),
        body: Center(
          child: Text('LDK is ready to use!'),
        ),
      ),
    );
  }
}

Next Steps

Now that LDK is installed, you can:

  1. Quick Start Guide: Learn the basics with a simple example
  2. Configuration Options: Explore all initialization options
  3. Authentication Guide: Set up user authentication
  4. CRUD Operations: Start building your app

Troubleshooting

Common Issues

Build Errors

Error: Minimum supported Gradle version is X.X Solution: Update your android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

Error: CocoaPods could not find compatible versions Solution: Update your Podfile and run:

cd ios
pod repo update
pod install --repo-update

Runtime Errors

Error: LDKConfigurationException: Base URL cannot be empty Solution: Ensure you're calling LDK.initialize() with a valid baseUrl.

Error: Connection refused Solution: Check that your Strapi server is running and accessible from your device/emulator.

Getting Help

If you encounter issues:

  1. Check our Troubleshooting Guide
  2. Search existing issues
  3. Create a new issue with details

Next: Quick Start Guide →