Repo Template Extension
Overview
The Repo Template Extension is a Visual Studio Code extension that allows you to create a new repository from a template with customizable variables. Right-click on a folder in the VS Code Explorer and select "Create New Repo from Template" to get started.
Features
- Add a right-click context menu item for folders in the VS Code Explorer.
- Prompt for user input to customize the repository template.
- Automatically generate a Dart file based on the provided template and user inputs.
Installation
- Download and install Visual Studio Code from here.
- Clone this repository or download the latest release.
- Open the project in Visual Studio Code.
- Install the required dependencies by running:
npm install
- Compile the extension by running:
npm run compile
Usage
- Open Visual Studio Code.
- Right-click on a folder in the Explorer pane.
- Select "Create New Repo from Template".
- Enter the required variables when prompted:
- variable1: Name of the class.
- variable2: Type of the class used in the response.
- variable4: Endpoint for the API call.
- The extension will generate a new Dart file in the selected folder based on the provided inputs.
Commands
1. Create New Repository Template
Command: repohelper.createNewRepo
Prompts for class name, model, request type (GET or POST), and endpoint name.
Generates a repository template.
2. Sync Cubit States
Command: repohelper.syncCubitStates
Identifies missing states in the Cubit state file.
Adds missing states.
Snippets
BlocProvider Static Method
Prefix: OMBlocProvider
Generates a static method for BlocProvider.of.
Prefix: OMpaginationModel
Generates a PaginationState model and PaginationStatus enum.
Pagination Cubit with Fetch and Load More
this depends on previous prefix
Prefix: OMpaginationCubit
Generates a Cubit with fetch and load more data methods.
Fetch All Item Data Method
Prefix: OMfetchAllItemData
Generates a method for fetching items in a Bloc cubit and emitting appropriate states.
Dart POST Method
Prefix: RPost
Generates a POST repository method for API interaction using Dio and Either.
Dart GET Method
Prefix: RGet
Generates a GET repository method for API interaction using Dio.
Flutter State Handling
Prefix: ErrorStateHandling
Generates a widget to handle different states in a Cubit builder.
Example
- Right-click on a folder and select "Create New Repo from Template".
- Enter the following values when prompted:
- variable1:
MyNewClass
- variable2:
User
- variable4:
loginEndpoint
- The extension generates a Dart file
MyNewClass.dart
with the following content:
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:your_project/helpers/dio_helper.dart';
import 'package:your_project/helpers/endpoints.dart';
import 'package:your_project/models/server_failure.dart';
import 'package:your_project/models/user.dart';
import 'dart:convert';
class MyNewClass {
Future<Either<String, User>> login() async {
try {
final response = await DioHelper.post(EndPoints.loginEndpoint, body: {
// Add your body here
}, headers: {
'Accept': 'application/json',
});
return Right(User.fromJson(jsonDecode(response.toString())));
} catch (e) {
if (e is DioException) {
return Left(ServerFailure.fromDioError(e).errMessage);
}
return Left(e.toString());
}
}
}