DEV Community

Cover image for Generate a flutter app from your Tomato App!
Fady Mondy
Fady Mondy

Posted on

Generate a flutter app from your Tomato App!

Image description

as we go to make everything easy, we are today releasing a very very good package to build a flutter app by just using 1 command to generate full CRUD from your schema and generated TomatoPHP files

Requirements

please check that you have flutter installed and working on your system by check

flutter doctor
Enter fullscreen mode Exit fullscreen mode

and you must have at least one emulator or device connected to your system

and you must have 2 packages working on your Laravel app Tomato Admin and Tomato CRM

after installing the package please make sure that you add a guard of accounts to your auth.php config like this

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'accounts' => [
            'driver' => 'session',
            'provider' => 'accounts',
        ],
    ],

...


    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'accounts' => [
            'driver' => 'eloquent',
            'model' => \TomatoPHP\TomatoCrm\Models\Account::class,
        ],
    ],

Enter fullscreen mode Exit fullscreen mode

Installation

composer require tomatophp/tomato-flutter
Enter fullscreen mode Exit fullscreen mode

now you are ready to generate a new app

to generate a new app you just need to run this command

php artisan tomato-flutter:generate
Enter fullscreen mode Exit fullscreen mode

Generate Module

to generate a new module you just need to run this command

php artisan tomato-flutter:module
Enter fullscreen mode Exit fullscreen mode

Generate Controller

to generate a new controller you just need to run this command

php artisan tomato-flutter:controller
Enter fullscreen mode Exit fullscreen mode

Generate Service

to generate a new service you just need to run this command

php artisan tomato-flutter:service
Enter fullscreen mode Exit fullscreen mode

Generate CRUD

to generate a new CRUD from any table on your tomato-php generated CRUDs just need to run this command

php artisan tomato-flutter:crud
Enter fullscreen mode Exit fullscreen mode

please note that the generated files will match only APIs generated by TomatoPHP and you need to add API routes to the api.php

Route::middleware(['auth:sanctum'])->name('api.')->group(function () {
    Route::get('customers', [\Modules\Customers\Http\Controllers\CustomerController::class, 'index'])->name('customers.index');
    Route::post('customers', [\Modules\Customers\Http\Controllers\CustomerController::class, 'store'])->name('customers.store');
    Route::get('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'show'])->name('customers.show');
    Route::post('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'update'])->name('customers.update');
    Route::delete('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'destroy'])->name('customers.destroy');
});
Enter fullscreen mode Exit fullscreen mode

Change Endpoint

if you like to change the endpoint to match your URL you can change it from the file

flutter/YOUR_APP/lib/config/Config.dart
Enter fullscreen mode Exit fullscreen mode

and change it to your endpoint, if you are using Android you check the app please make the endpoint hit to http://10.0.2.2:8000/api and run

php artisan serv
Enter fullscreen mode Exit fullscreen mode

on your app.

Top comments (0)