PHPackages                             bashar-shaeb/laravel-flutter-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bashar-shaeb/laravel-flutter-generator

ActiveLibrary[API Development](/categories/api)

bashar-shaeb/laravel-flutter-generator
======================================

A Laravel package that bridges Laravel backend with Flutter frontend by generating complete Flutter features (models, services, UI components) from Laravel models and routes

00PHPCI failing

Since May 24Pushed 11mo agoCompare

[ Source](https://github.com/Basharshaeb/laravel-flutter-generator)[ Packagist](https://packagist.org/packages/bashar-shaeb/laravel-flutter-generator)[ RSS](/packages/bashar-shaeb-laravel-flutter-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Flutter Bridge
======================

[](#laravel-flutter-bridge)

A comprehensive Laravel package that bridges your Laravel backend with Flutter frontend by automatically generating complete Flutter features (models, services, UI components) from your existing Laravel Eloquent models and routes.

Features
--------

[](#features)

- 🚀 **Automatic Code Generation**: Generate complete Flutter features from Laravel models
- 📱 **UI Components**: Create forms, lists, and detail views automatically
- 🔗 **API Integration**: Generate Flutter services that integrate with Laravel API endpoints
- 🏗️ **SOLID Principles**: Clean, maintainable code following best practices
- 🎨 **Customizable Templates**: Modify generation templates to fit your needs
- 🧪 **Comprehensive Testing**: Full test coverage for reliable code generation
- 🔄 **CRUD Operations**: Complete Create, Read, Update, Delete functionality
- 🎯 **Type Safety**: Full Dart null safety support
- 📊 **Relationship Support**: Handle Eloquent model relationships
- ⚡ **Performance Optimized**: Efficient code generation with minimal dependencies

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require bashar-shaeb/laravel-flutter-generator
```

Publish the configuration file:

```
php artisan vendor:publish --provider="BasharShaeb\LaravelFlutterGenerator\FlutterGeneratorServiceProvider" --tag="flutter-generator-config"
```

Optionally, publish the templates for customization:

```
php artisan vendor:publish --provider="BasharShaeb\LaravelFlutterGenerator\FlutterGeneratorServiceProvider" --tag="flutter-generator-templates"
```

Quick Start
-----------

[](#quick-start)

### 1. Generate a Dart model from Laravel model:

[](#1-generate-a-dart-model-from-laravel-model)

```
php artisan flutter:generate-model User
```

### 2. Generate API service for a model:

[](#2-generate-api-service-for-a-model)

```
php artisan flutter:generate-service User --with-routes
```

### 3. Generate complete feature (model + service + UI):

[](#3-generate-complete-feature-model--service--ui)

```
php artisan flutter:generate-feature User
```

### 4. Generate everything for all models:

[](#4-generate-everything-for-all-models)

```
php artisan flutter:generate-all
```

### 5. Generate for specific models only:

[](#5-generate-for-specific-models-only)

```
php artisan flutter:generate-all --models=User,Post,Category
```

Command Options
---------------

[](#command-options)

### Global Options

[](#global-options)

- `--force`: Overwrite existing files without confirmation
- `--all`: Process all available models

### Feature-specific Options

[](#feature-specific-options)

- `--skip-model`: Skip model generation
- `--skip-service`: Skip service generation
- `--skip-widgets`: Skip widget generation
- `--skip-screens`: Skip screen generation
- `--with-routes`: Include route analysis for custom API methods

Configuration
-------------

[](#configuration)

The package configuration file is published to `config/flutter-generator.php`. Key configuration options:

### Output Paths

[](#output-paths)

```
'output' => [
    'base_path' => base_path('flutter_output'),
    'models_path' => 'models',
    'services_path' => 'services',
    'widgets_path' => 'widgets',
    'screens_path' => 'screens',
],
```

### API Configuration

[](#api-configuration)

```
'api' => [
    'base_url' => env('FLUTTER_API_BASE_URL', 'http://localhost:8000/api'),
    'timeout' => 30,
    'authentication' => [
        'type' => 'bearer', // bearer, basic, none
        'header_name' => 'Authorization',
    ],
],
```

### Code Generation Settings

[](#code-generation-settings)

```
'generation' => [
    'architecture' => 'provider', // provider, bloc, riverpod
    'null_safety' => true,
    'use_freezed' => false,
    'use_json_annotation' => true,
    'generate_tests' => true,
    'generate_documentation' => true,
],
```

### Model Analysis

[](#model-analysis)

```
'model_analysis' => [
    'include_relationships' => true,
    'include_accessors' => true,
    'include_timestamps' => true,
    'excluded_attributes' => [
        'password',
        'remember_token',
        'email_verified_at',
    ],
],
```

Generated Code Structure
------------------------

[](#generated-code-structure)

```
flutter_output/
├── models/
│   ├── user.dart
│   ├── user.g.dart (if using json_annotation)
│   └── post.dart
├── services/
│   ├── api_service.dart (base HTTP client)
│   ├── user_service.dart
│   └── post_service.dart
├── widgets/
│   ├── user_form.dart
│   ├── user_list.dart
│   ├── user_card.dart
│   └── post_form.dart
└── screens/
    ├── user_list_screen.dart
    ├── user_detail_screen.dart
    ├── user_create_screen.dart
    └── user_edit_screen.dart

```

Example Generated Code
----------------------

[](#example-generated-code)

### Dart Model

[](#dart-model)

```
import 'package:json_annotation/json_annotation.dart';

part 'user.g.dart';

@JsonSerializable()
class User {
  final int id;
  final String name;
  final String email;
  final DateTime? emailVerifiedAt;
  final bool isActive;

  const User({
    required this.id,
    required this.name,
    required this.email,
    this.emailVerifiedAt,
    required this.isActive,
  });

  factory User.fromJson(Map json) => _$UserFromJson(json);
  Map toJson() => _$UserToJson(this);

  User copyWith({
    int? id,
    String? name,
    String? email,
    DateTime? emailVerifiedAt,
    bool? isActive,
  }) {
    return User(
      id: id ?? this.id,
      name: name ?? this.name,
      email: email ?? this.email,
      emailVerifiedAt: emailVerifiedAt ?? this.emailVerifiedAt,
      isActive: isActive ?? this.isActive,
    );
  }
}
```

### API Service

[](#api-service)

```
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../models/user.dart';
import 'api_service.dart';

class UserService {
  final ApiService _apiService;
  final String _endpoint;

  UserService(this._apiService, this._endpoint);

  Future getAll({int? page, Map? filters}) async {
    try {
      final queryParams = {};
      if (page != null) queryParams['page'] = page.toString();

      final response = await _apiService.get(_endpoint, queryParams: queryParams);
      final List data = response['data'] ?? response;
      return data.map((json) => User.fromJson(json)).toList();
    } catch (e) {
      throw Exception('Failed to fetch User list: $e');
    }
  }

  Future getById(int id) async {
    try {
      final response = await _apiService.get('$_endpoint/$id');
      final data = response['data'] ?? response;
      return User.fromJson(data);
    } catch (e) {
      throw Exception('Failed to fetch User with ID $id: $e');
    }
  }

  Future create(Map data) async {
    try {
      final response = await _apiService.post(_endpoint, data);
      final responseData = response['data'] ?? response;
      return User.fromJson(responseData);
    } catch (e) {
      throw Exception('Failed to create User: $e');
    }
  }

  Future update(int id, Map data) async {
    try {
      final response = await _apiService.put('$_endpoint/$id', data);
      final responseData = response['data'] ?? response;
      return User.fromJson(responseData);
    } catch (e) {
      throw Exception('Failed to update User with ID $id: $e');
    }
  }

  Future delete(int id) async {
    try {
      await _apiService.delete('$_endpoint/$id');
      return true;
    } catch (e) {
      throw Exception('Failed to delete User with ID $id: $e');
    }
  }
}
```

Integration with Flutter Project
--------------------------------

[](#integration-with-flutter-project)

1. **Copy generated files** to your Flutter project:

```
cp -r flutter_output/* your_flutter_project/lib/
```

2. **Add dependencies** to your `pubspec.yaml`:

```
dependencies:
  flutter:
    sdk: flutter
  http: ^1.1.0
  json_annotation: ^4.8.1
  provider: ^6.1.1  # if using Provider architecture

dev_dependencies:
  build_runner: ^2.4.7
  json_serializable: ^6.7.1
```

3. **Run code generation** (if using json\_annotation):

```
flutter packages pub run build_runner build
```

4. **Initialize API service** in your app:

```
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: UserListScreen(),
    );
  }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Templates

[](#custom-templates)

You can customize the generated code by modifying the published templates in `resources/views/flutter-generator/`.

### Excluding Models

[](#excluding-models)

Add models to exclude in your configuration:

```
'excluded_models' => [
    'App\\Models\\InternalModel',
    'Spatie\\Permission\\Models\\Role',
],
```

### Route Integration

[](#route-integration)

Use the `--with-routes` flag to analyze your API routes and generate additional service methods:

```
php artisan flutter:generate-service User --with-routes
```

This will analyze routes like:

- `GET /api/users/{user}/posts` → `getUserPosts(int userId)`
- `POST /api/users/{user}/activate` → `activateUser(int userId)`

Testing
-------

[](#testing)

Run the package tests:

```
composer test
```

Run with coverage:

```
composer test-coverage
```

Requirements
------------

[](#requirements)

- PHP 8.1+ (8.2, 8.3, 8.4 supported)
- Laravel 10.0+, 11.0+, or 12.0+
- Flutter 3.0+
- Doctrine DBAL 3.0+ or 4.0+ (for database schema analysis)

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Author
------

[](#author)

**BasharShaeb** - [GitHub Profile](https://github.com/BasharShaeb)

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for a list of changes.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9646dafd413db680f6f6710a8b107dbda2678e3e24f0099bf9b49bf8ade824d?d=identicon)[Basharshaeb](/maintainers/Basharshaeb)

---

Top Contributors

[![Basharshaeb](https://avatars.githubusercontent.com/u/58868417?v=4)](https://github.com/Basharshaeb "Basharshaeb (7 commits)")

### Embed Badge

![Health badge](/badges/bashar-shaeb-laravel-flutter-generator/health.svg)

```
[![Health](https://phpackages.com/badges/bashar-shaeb-laravel-flutter-generator/health.svg)](https://phpackages.com/packages/bashar-shaeb-laravel-flutter-generator)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
