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.

Source Distribution

ptfgen-1.0.3.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptfgen-1.0.3-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file ptfgen-1.0.3.tar.gz.

File metadata

  • Download URL: ptfgen-1.0.3.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for ptfgen-1.0.3.tar.gz
Algorithm Hash digest
SHA256 60dfb902f1feb9e4621f50305b577facf5c95413c46a090518bb8560633b3b74
MD5 280cf8b7bee1dc469e96385cbe3e1f07
BLAKE2b-256 74d5b5b374ad3a012ef9755bf3794a827f5fd943d8b74b17c5ef64f32df0885e

See more details on using hashes here.

File details

Details for the file ptfgen-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: ptfgen-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for ptfgen-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 edb5023fe77acf774f3b1b94b48cfeda4435ff1523acca0cb4afcd02e6455a94
MD5 a43fabe88453067f753b52fe2c0e54fa
BLAKE2b-256 5fba87a8103e2c7cf62c13358961e840e00392cb690736ddbd81ac179d5b43e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page