Awesome Flutter extensions to remove boilerplate

Overview

Awesome Flutter Extensions

Awesome flutter extensions to remove boilerplate

Installation

  1. Install using the Terminal:
flutter pub add awesome_flutter_extensions
  1. Install adding the dependency in the pubspec.yaml:
dependencies:
  awesome_flutter_extensions: ^0.0.1 # Use the latest version from pub.dev
  1. Install using Pubspec Assist (VSCode extensions):

Open the command palette:

  • (⇧ ⌘ P) on Mac
  • (Ctrl ⇧ P) on Windows

Then type Pubspec assist.. until you'll get Pubspec Assist: Add/Update dependencies.

Here type the name of the package: awesome_flutter_extensions and press ENTER ↵.

Get Started

First of all, let's import the extensions with:

import 'package:awesome_flutter_extensions/awesome_flutter_extensions.dart';

or

import 'package:awesome_flutter_extensions/all.dart';

To learn the differences between them, continue reading.

Usage

There are many extensions in this library. So I decided to break them up into groups. The groups currently available are:

Why this split? After creating extensions upon extensions, I admit that with context you could access an infinite number of things. That's why I decided to split them up.

Hey, but a library to avoid boilerplate and I have to write so much code? If you prefer to have all extensions available directly with the context, import this instead:

import 'package:awesome_flutter_extensions/all.dart';

Navigator

To push a page you can use:

// before
Navigator.of(context).push<void>(
    MaterialPageRoute(
    builder: (context) => const SecondPage(),
  ),
);
// after
context.navigator.push<void>(
    MaterialPageRoute(
    builder: (context) => const SecondPage(),
  ),
);
// with the `all.dart` import
context.push<void>(
    MaterialPageRoute(
    builder: (context) => const SecondPage(),
  ),
);

All the extensions available are:

  • canPop
  • maybePop
  • pop
  • popUntil
  • push
  • popAndPushNamed
  • pushAndRemoveUntil
  • pushNamed
  • pushNamedAndRemoveUntil
  • pushReplacement
  • pushReplacementNamed
  • removeRoute
  • removeRouteBelow
  • replace
  • replaceRouteBelow

Sizes

To get the width of the screen, use:

// before
MediaQuery.of(context).size.width
// after
context.sizes.width;
// with the `all.dart` import
context.width

All the extensions available are:

  • width
  • height
  • padding
  • viewInsets
  • systemGestureInsets
  • viewPadding
  • devicePixelRatio
  • textScaleFactor

TextStyles

To get the headline1 text style use:

// before
Theme.of(context).textTheme.headline1!
// after
context.textStyles.h1
// with the `all.dart` import
context.h1

All the extensions available are:

  • h1
  • h2
  • h3
  • h4
  • h5
  • h6
  • bodyText1
  • bodyText2
  • caption
  • button
  • overline
  • subtitle1
  • subtitle2

You can also change the font weight directly using:

// normally
context.textStyles.h1.semiBold
// with the `all.dart` import
context.h1.semiBold

All the font weights available are:

  • thick
  • extraBold
  • bold
  • semiBold
  • medium
  • regular
  • light
  • extraLight
  • thin

You can also change the font style directly using:

// normally
context.textStyles.h1.italic
// with the `all.dart` import
context.h1.italic

All the font weights available are:

  • normal
  • italic

Colors

To get the primaryColor from the theme use:

// before
Theme.of(context).primaryColor
// after
context.colors.primary
// with the `all.dart` import
context.primaryColor

You can also get the colorScheme colors using:

// before
Theme.of(context).colorScheme
// after
context.colors.scheme
// with the `all.dart` import
context.colorScheme

All the extensions available are:

  • primary
  • primaryLight
  • primaryDark
  • accent
  • canvas
  • shadow
  • scaffoldBackground
  • bottomAppBar
  • card
  • divider
  • focus
  • hover
  • highlight
  • splash
  • selectedRow
  • unselectedWidget
  • disabled
  • button
  • secondaryHeader
  • background
  • dialogBackground
  • indicator
  • hint
  • error
  • toggleableActive
  • scheme

In the all.dart file the names have the Color word after them, except for scheme which becomes colorScheme.

Themes

To get the appBarTheme, use:

// before
Theme.of(context).appBarTheme
// after
context.themes.appBar;
// with the `all.dart` import
context.appBarTheme

All the extensions available are:

  • button
  • toggleButtons
  • text
  • primaryText
  • accentText
  • inputDecoration
  • icon
  • primaryIcon
  • accentIcon
  • slider
  • tabBar
  • tooltip
  • card
  • chip
  • appBar
  • scrollbar
  • bottomAppBar
  • dialog
  • floatingActionButton
  • navigationRail
  • snackBar
  • bottomSheet
  • popupMenu
  • banner
  • divider
  • buttonBar
  • bottomNavigationBar
  • timePicker
  • textButton
  • elevatedButton
  • outlinedButton
  • textSelection
  • dataTable
  • checkbox
  • radio
  • switchTheme
  • cupertinoOverride

In the all.dart file the names have the Theme word after them, except for switchTheme that is equal.

Contributing

Contributions are welcomed!

Here is a curated list of how you can help:

  • Report bugs
  • Report parts of the documentation that are unclear
  • Update the documentation / add examples
  • Implement new features by making a pull-request

If you enjoyed the library, like it.

You might also like...

Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.

Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.

Flutter UI Boilerplate "Sharing for fun" Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file f

Dec 1, 2022

A flutter boilerplate project containing bloc, pedantic, hive, easy_translations and more!

A flutter boilerplate project containing bloc, pedantic, hive, easy_translations and more!

Flutter Production Boilerplate A flutter project containing bloc, flutter_lints, hive, easy_translations and more! This repository is the starting poi

Dec 26, 2022

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

flutter-app boilerplate This repo is a boilerplate to create flutter application easily. It is based on GetX. More info about GetX here. The app has b

Dec 3, 2022

Boilerplate for Flutter + GetX MVVM

flutter_getx_boilerplate A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

May 31, 2022

A boilerplate project created in flutter using MobX and Provider

Boilerplate Project A boilerplate project created in flutter using MobX and Provider. Boilerplate supports both web and mobile, clone the appropriate

Jan 20, 2022

A boilerplate project for Flutter using RiverPod, Dio, auto_route

Flutter Boilerplate A boilerplate project for Flutter using RiverPod, Dio, auto_route, Freezed and generated with very_good_cli. This is a very simple

Dec 9, 2022

A basic boilerplate template for starting a Flutter GetX project. GetX, Dio, MVVM, get CLI, Localization, Pagination etc are implemented.

A basic boilerplate template for starting a Flutter GetX project. GetX, Dio, MVVM, get CLI, Localization, Pagination etc are implemented.

Flutter GetX Template (GetX, Dio, MVVM) This Flutter Template using GetX package for State management, routing and Dependency Injection (bindings). We

Jan 9, 2023

Flutter boilerplate

boilerpalta Flutter boilerplate project Getting Started This project is a starting boilerplate based on the official project skeleton from flutter 2.5

Nov 25, 2021

Flutter boilerplate with TDD architecture

flutter_tdd_architecture A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

May 25, 2022
Comments
  • Feat initial release

    Feat initial release

    Description

    • Add the example folder
    • Add more details in the readme
    • Add all.dart file with all the extensions

    Type of Change

    • [X] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] 🧹 Code refactor
    • [X] 📝 Documentation
    • [X] 🗑️ Chore
    opened by nank1ro 0
Releases(v0.0.1)
Owner
Alexandru Mariuti
Flutter developer
Alexandru Mariuti
Awesome aurora gradient - Awesome Aurora Gradients for flutter

Awesome Aurora Gradient Provides a simple but powerful gradient extension method

null 2 Feb 25, 2022
Awesome Notifications add-on plugin to enable push notifications through Firebase Cloud Messaging with all awesome notifications features.

Awesome Notifications FCM Awesome Notifications add-on to send push notifications using FCM (Firebase Cloud Messaging), with all awesome notifications

Rafael Setragni 8 Jan 4, 2023
The prime objective of this app is to store the real time information of the user using firebase cloud firestore and also can delete, remove and update the customer information

crud_firestore A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Muhammad Zakariya 0 Mar 15, 2022
The Reactive Extensions for Dart

RxDart About RxDart extends the capabilities of Dart Streams and StreamControllers. Dart comes with a very decent Streams API out-of-the-box; rather t

ReactiveX 3.2k Dec 20, 2022
Functional extensions to Dart collections.

collection_ext A set of extension methods for Dart collections, designed for the purpose of making it easier to write concise, functional-programming-

Yingxin Wu 7 Nov 21, 2022
Various extensions on BuildContext to access inherited widget's state

context_extentions Getting inherited widget's state var themeData = context.theme; var scaffold = context.scaffold; var navigator = context.navi

Ali Ghanbari 4 Sep 23, 2021
Enum extendable - Dart code generator. Generates enum extensions code.

Generates code for the extension on an enum. Overview Being able to add fields and methods to an enum. Let's say we have the following enum: enum Math

null 0 Jan 10, 2022
Material io ext - A collection of extensions for creating widgets following material.io guidelines

material_io_ext It is a collection of extensions for creating widgets following

BetterX.io 3 Jan 28, 2022
Package provides light widgets [for Linkify, Clean] and extensions for strings that contain bad words/URLs/links/emails/phone numbers

Package provides light widgets [for Linkify, Clean] and extensions for strings that contain bad words/URLs/links/emails/phone numbers

BetterX.io 4 Oct 2, 2022
Extensions and principles for modern Dart development.

neodart Neo-Dart, or "new" Dart, is a series of recommended packages and principles that break out of classic conventions ("we've always done it that

Neo Dart 10 Dec 6, 2022