Easy Git Hooks for Flutter

Easy Git Hooks for Flutter

Easy Git Hooks for Flutter. Git hooks for various activities like linting, formatting, testing, etc. within Flutter projects using Lefthook. Git Hooks Explained using Flutter, by Roberta. With Flutter, it is very easy to have code.

Automate your workflow with git hooks for various activities like linting, formatting, testing, etc. within Flutter projects using Lefthook

As projects grow larger and the codebase is continuously edited by multiple developers at the same time, the need for maintaining code standards and code quality becomes really essential. Of course, that responsibility would lie with the individual developers but this process can be made really efficient and painless using the power of git hooks.

Git hooks are a way of firing off custom scripts/actions before executing a git command — commit, push, etc. There are a lot of git hooks available to use as  documented in the official git website, but in this article, we are going to focus on primarily two: pre-push and pre-commit along with how to easily implement them in a Flutter project.

There is a great  article¹ by Roberta, that explains how to set up custom git hooks in Flutter projects by modifying the content in the .git folder. The .git folder is a hidden folder at the root of your repository. But there is also another way to implement this, using Lefthook² — a polyglot git hooks manager.

Firstly, we need to install lefthook globally. Based on your environment, there are a few options —

If you have Node.js installed: npm install -g @arkweid/lefthook

If you’re in a Ruby-based environment: gem install lefthook

_You may need to run these commands as `sudo_`

That’s it, lefthook is now available for use. Navigate to your project root and run — lefthook install

The `lefthook install_` command has to be run once per project / repository_

Lefthook works by using a YAML file that is placed in the project root. So let’s create that file — lefthook.yaml

This file defines which git hooks should be used and which scripts/commands should be run during those hooks. With Flutter, it is very easy to have code that is formatted differently based on the individual developers' preference. To resolve this, we can use the commands available in the Flutter SDK to standardize our code before committing/pushing to version control.

Before committing, we’re going to configure two commands. The first one to lint the dart code using default rules from the Flutter SDK and the second to format the code. The file starts with the name of the hook followed by an array of commands on the next indentation level. I have defined two commands —

flutter dart programming git

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

What is Flutter and why you should learn it?

Flutter is an open-source UI toolkit for mobile developers, so they can use it to build native-looking Android and iOS applications from the same code base for both platforms. Flutter is also working to make Flutter apps for Web, PWA (progressive Web-App) and Desktop platform (Windows,macOS,Linux).

Flutter - Complex JSON Serialization in Dart | 3 Methods | JSON to Dart/Flutter

Learn to convert any complex JSON data structures into Dart data classes in Flutter using these 3 methods.Web 1 : https://javiercbk.github.io/json_to_dart/We...

Dart Programming Tutorial | Learn the Dart for Flutter

Learn Dart Programming for Flutter- Beginners Tutorial - Udemy Free Course

6 Things About HTTP Request in Dart For Beginners

Here is an http request to get a user's data using GET request, First, we have to make an async function that returns a type. If you are here and a beginner, that means you want to learn everything about making an API request using Dart in Flutter, then you are in the right place for the HTTP tutorial.