Skip to main content

A code generator for Flutter

Project description

Code generator for Flutter apps

Installation:

Install using pip3:

Open Terminal and run:

$ brew install python
$ pip3 install ptfgen

Update:

$ pip3 install -U ptfgen

Uninstall:

$ pip3 uninstall ptfgen

1. Create Template:

1.1. Base Template:

The Base Template contains necessary files for a screen using the Flutter Clean Architecture pattern.

Open Terminal, navigate to your flutter project folder you want to save the files and run:

$ ptfgen template base <Scene_Name>

Example:

$ ptfgen template base LoginEmail

Output:

Successfully created files:
    ./lib/assembler.dart
    ./lib/scenes/login_email/login_email_viewmodel.dart
    ./lib/scenes/login_email/login_email_navigator.dart
    ./lib/scenes/login_email/login_email_usecase.dart
    ./lib/scenes/login_email/login_email_assembler.dart
    ./lib/scenes/login_email/login_email_view.dart
    ./lib/mock/login_email_usecase_mock.dart
    ./test/unit_test/login_email/login_email_viewmodel_test.dart
    ./test/unit_test/login_email/login_email_usecase_mock.dart
    ./test/unit_test/login_email/login_email_navigator_mock.dart

2. Create models from JSON:

Copy the json then run the command:

$ ptfgen json <Model_Name> [-p]

Options:

-p, --print: print the result.

Example:

Copy the json:

{
    "employees":[  
        {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},  
        {"name":"Bob", "email":"bob32@gmail.com"},  
        {"name":"Jai", "email":"jai87@gmail.com"}  
    ]
} 

then run:

$ ptfgen json Company

Output:

The result has been copied to the pasteboard.

Content in the pasteboard:

import 'package:pt_object_mapper/pt_object_mapper.dart'; 

/// Remember register to Mappable.factories
/// Mappable.factories[Employee] = () => Employee();

class Employee with Mappable {
  String name;
  String email;

  @override
  void mapping(Mapper map) {
    map("name", name, (v) => name = v);
    map("email", email, (v) => email = v);
  }
}

/// Remember register to Mappable.factories
/// Mappable.factories[Company] = () => Company();

class Company with Mappable {
  List<Employee> employees;

  @override
  void mapping(Mapper map) {
    map<Employee>("employees", employees, (v) => employees = v);
  }
}

3. Create a mock class for a protocol/function:

Copy the abstract/function then run:

$ ptfgen mock [-p]

Options:

-p, --print: print the result.

Example:

Copy the abstract:

abstract class SignUpEmailUseCaseType {
  Stream<User> signUpWithEmail(String email, String password);
  ValidationResult validateEmail(String email);
  ValidationResult validatePassword(String password);
}

then run:

$ ptfgen mock

Output:

The result has been copied to the pasteboard.

Content in the pasteboard:

class SignUpEmailUseCaseMock implements SignUpEmailUseCaseType {

    /// signUpWithEmail

    var signUpWithEmail_Called = false;
    var signUpWithEmail_ReturnValue = Stream<User>.value(null);

      Stream<User> signUpWithEmail(String email, String password) {
        signUpWithEmail_Called = true;
        return signUpWithEmail_ReturnValue;
    } 

    /// validateEmail

    var validateEmail_Called = false;
    var validateEmail_ReturnValue = ValidationResult.valid();

      ValidationResult validateEmail(String email) {
        validateEmail_Called = true;
        return validateEmail_ReturnValue;
    } 

    /// validatePassword

    var validatePassword_Called = false;
    var validatePassword_ReturnValue = ValidationResult.valid();

      ValidationResult validatePassword(String password) {
        validatePassword_Called = true;
        return validatePassword_ReturnValue;
    } 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ptfgen, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size ptfgen-1.0.3.tar.gz (15.7 kB) File type Source Python version None Upload date Hashes View
Filename, size ptfgen-1.0.3-py3-none-any.whl (22.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page