Build context - Access most used properties in your BuildContext instance.

Overview

Languages: English | Brazilian Portuguse

Logo

BuildContext

Access most used properties in your BuildContext instance. This package relies on Dart's extension to provide easy access for the most used properties and functions that depends on the BuildContext instance.

Available Extensions

I update this package frequently to add more extensions, bellow you can see the currently available extensions in the latest version.

From the MediaQuery. Access properties right in the context instance. Available extensions:

  • context.mediaQuerySize

  • context.orientation

  • context.mediaQueryPadding

  • context.alwaysUse24HourFormat

  • context.devicePixelRatio

  • context.platformBrightness

  • context.textScaleFactor

  • context.isLandscape

  • context.isPortrait

  • context.mediaQueryViewPadding

  • context.mediaQueryViewInsets

  • context.mediaQueryShortestSide

  • context.isPhone

  • context.isTablet

  • context.isSmallTablet

  • context.isLargeTablet

From the Navigator class. Navigate with ease. Available extensions:

  • context.push()
  • context.pop()
  • context.canPop()
  • context.pushNamed()
  • context.popUntil()

From the Theme class. Access your themes right in the context instance. Available extensions:

  • context.theme
  • context.textTheme
  • context.primaryTextTheme
  • context.accentTextTheme
  • context.bottomAppBarTheme
  • context.bottomSheetTheme
  • context.appBarTheme
  • context.backgroundColor
  • context.primaryColor
  • context.buttonColor
  • context.scaffoldBackgroundColor
  • context.platform
  • context.isAndroid
  • context.isIOS
  • context.isWindows
  • context.isMacOS
  • context.isLinux
  • context.isFuchsia
  • context.headline1
  • context.headline2
  • context.headline3
  • context.headline4
  • context.headline5
  • context.headline6
  • context.subtitle1
  • context.bodyText1
  • context.bodyText2
  • context.caption
  • context.button
  • context.subtitle2
  • context.overline

From Scaffold class. Handle your scaffold in their context.

Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

  • context.openDrawer()
  • context.openEndDrawer()
  • context.showSnackBar()
  • context.hideCurrentSnackBar()
  • context.removeCurrentSnackBar()
  • context.showBottomSheet()

From Form.of(context) class.

Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

  • context.form.validate()
  • context.form.reset()
  • context.form.save()

From FocusScope.of(context) class.

  • context.focusScope.hasFocus

  • context.focusScope.isFirstFocus

  • context.focusScope.canRequestFocus

  • context.focusScope.hasPrimaryFocus

  • context.focusScope.unfocus()

  • context.focusScope.nextFocus()

  • context.focusScope.requestFocus()

  • context.focusScope.previousFocus()

  • context.focusScope.setFirstFocus()

  • context.focusScope.consumeKeyboardToken()

  • context.closeKeyboard()

From ModalRoute.of(context) class.

  • context.modalRoute
  • context.routeSettings

Install

Add it in your pubspec.yaml:

dependencies:
  build_context: ^3.0.0

Import it where you want to use it e.g, in your widget's file.

import "package:build_context/build_context.dart";

Here is a usage example:

import 'package:flutter/material.dart';
import "package:build_context/build_context.dart";

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: context.scaffoldBackgroundColor, // There is no Theme.of(context)
      body: Center(
        child: GestureDetector(
          onTap: () => context.pushNamed('/detailsPage'), // we use only context not Navigator.of(context)
          child: Text(
            'Press Me',
            style: context.primaryTextTheme.title, // we use only context not Theme.of(context)
          ),
        ),
      ),
    );
  }
}

Support

You liked this package? then give it a star. If you want to help then:

  • Start this repository
  • Send a Pull Request with new features
  • Share this package
  • Create issues if you find a Bug or want to suggest something
Comments
  • Errors in Flutter  v1.18.0-7.0.pre.19

    Errors in Flutter v1.18.0-7.0.pre.19

    Hi. Thanks a lot for this package. What is the maximum supported version of Flutter?

    In v1.18.0-7.0.pre.19 I have 2 errors:

    Compiler message:
    ../../.pub-cache/hosted/pub.dartlang.org/build_context-1.1.0/lib/src/build_context_impl.dart:44:38: Error: This expression has type 'void' and can't be used.
      bool pop<T>(T result) => Navigator.pop(this, result);
                                         ^
    ../../.pub-cache/hosted/pub.dartlang.org/build_context-1.1.0/lib/src/build_context_impl.dart:142:23: Error: No named parameter with the name 'focusPrevious'.
          _node().unfocus(focusPrevious: focusPrevious);
    
    opened by vasilich6107 2
  • Migrated null safety

    Migrated null safety

    Description

    I propose this pull request to migrate this plugin to null safety as it is the way to go now that Flutter 2 has been released.

    Here are the changes I introduced:

    • Update SDK dependency version to 2.12.0+
    • Run dart migrate on existing code to remove unsafe nulls (for the package & example)
    • Add a new version (3.0.0) to the changelog (as recommended)
    • Migrated in the example to the new TextTheme version

    Please check everything twice!

    Testing

    • [x] Tested it manually on a Android emulator

    Related tickets

    Closes #19

    opened by nilsreichardt 1
  • Added closeKeyboard()

    Added closeKeyboard()

    Problem

    To close the keyboard you have to call context.focusScope.requestFocus(FocusNode()). Its' not only a lot of code, but it's also hard to read, because you have to know, that requestFocus(FocusNode()) will close the keyboard.

    Solution

    A better solution is context.closeKeyboard(). It's very short and easy to read 👍

    opened by nilsreichardt 1
  • Added TargetPlatform

    Added TargetPlatform

    Sometimes you need to show different widgets for the platforms. To achieve this, you can use Theme.of(context).platform == TargetPlatform.isAndroid. But this is a little bit long. So I added this methods:

    context.platform => TragetPlatform context.isAndroid => bool context.isIOS => bool context.isWindows => bool context.isMacOS => bool context.isLinux => bool context.isFuchsia => bool

    Short questions: context.isIOS or context.isIOs? context.isMacOS or context.isMacOs?

    opened by nilsreichardt 0
  • Add dialog support extensions

    Add dialog support extensions

    To show a dialog, we must add the context parameter to the function. It would be cool if we could show a dialog from the BuildContext.

    For example:

    Previous:

    showDialog(
          context: context,
          ....
    );
    

    Now:

    context.showDialog(...);
    
    opened by bdlukaa 0
Releases(3.0.0)
  • 3.0.0(Mar 10, 2021)

    • Migrated to null safety
    • Migration to ScaffoldMessenger

    Added support for:

    *context.platform *context.headline1 *context.headline2 *context.headline3 *context.headline4 *context.headline5 *context.headline6 *context.subtitle1 *context.bodyText1 *context.bodyText2 *context.caption *context.button *context.subtitle2 *context.overline

    *context.modalRoute *context.routeSettings

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Apr 23, 2020)

    Available Extensions

    From the MediaQuery. Access properties right in the context instance. Available extensions:

    • context.mediaQuerySize

    • context.orientation

    • context.mediaQueryPadding

    • context.alwaysUse24HourFormat

    • context.devicePixelRatio

    • context.platformBrightness

    • context.textScaleFactor

    • context.isLandscape

    • context.isPortrait

    • context.mediaQueryViewPadding

    • context.mediaQueryViewInsets

    • context.mediaQueryShortestSide

    • context.isPhone

    • context.isTablet

    • context.isSmallTablet

    • context.isLargeTablet

    From the Navigator class. Navigate with ease. Available extensions:

    • context.push()
    • context.pop()
    • context.canPop()
    • context.pushNamed()
    • context.popUntil()

    From the Theme class. Access your themes right in the context instance. Available extensions:

    • context.textTheme
    • context.primaryTextTheme
    • context.accentTextTheme
    • context.bottomAppBarTheme
    • context.bottomSheetTheme
    • context.appBarTheme
    • context.backgroundColor
    • context.primaryColor
    • context.buttonColor
    • context.scaffoldBackgroundColor

    From Scaffold class. Handle your scaffold in their context.

    Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

    • context.openDrawer()
    • context.openEndDrawer()
    • context.showSnackBar()
    • context.hideCurrentSnackBar()
    • context.removeCurrentSnackBar()
    • context.showBottomSheet()

    From Form.of(context) class.

    Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

    • context.form.validate()
    • context.form.reset()
    • context.form.save()

    From FocusScope.of(context) class.

    • context.focusScope.hasFocus

    • context.focusScope.isFirstFocus

    • context.focusScope.canRequestFocus

    • context.focusScope.hasPrimaryFocus

    • context.focusScope.unfocus()

    • context.focusScope.nextFocus()

    • context.focusScope.requestFocus()

    • context.focusScope.previousFocus()

    • context.focusScope.setFirstFocus()

    • context.focusScope.consumeKeyboardToken()

    Source code(tar.gz)
    Source code(zip)
Owner
Pedro Massango
Self-taught Software Engineer. Not quite good at it yet, but I'm learning :)
Pedro Massango
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
Flutter-context-menus - A flutter package to show context menus on right-click or long-press

context_menus A package to show context menus on right-click or long-press. ?? I

null 0 Jan 18, 2022
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Vehement 8 Nov 26, 2022
A collection of pixel-perfect iOS-styled components and properties for Flutter, following the official guidelines.

cupertinew ⚠️ Experimental and work in progress ⚠️ A collection of pixel-perfect iOS-styled components and properties for Flutter, following the offic

Jeroen Meijer (Jay) 30 Nov 10, 2022
Dart package to retrieve Transmission data from remote instance

transmission Dart package to talk to a Transmission torrent instance, for a flutter package including UI widget please check transmission Getting Star

L.I.S.A. 6 Nov 6, 2022
A Flutter plugin to retrieve the Firebase App Instance ID

firebase_instance_id A Flutter plugin to retrieve the Firebase App Instance ID# device_unlock How does it work App Instance Id is an unique identifier

Cíngulo 1 Jan 21, 2022
A script to disable and re-enable CORS checks for Flutter's Chrome instance

A script to disable and re-enable CORS checks for Flutter's Chrome instance Note This script only disables CORS checks for local testing, and will not

Rexios 26 Nov 15, 2022
Mixins is a package for shortening the use of some widgets or properties.

Usage It's not a great package, just help us to code briefly, everyone can make their own easily. To use this plugin, add mixins as a dependency in yo

Ashta 5 Nov 8, 2022
FlutterNavigator is a dart library for dealing with the Navigator API without a build context

FlutterNavigator is a dart library for dealing with the Navigator API without a build context. This package wraps the NavigatorKey and provides a cleaner service for navigating without context in your flutter application.

Luke Moody 10 Oct 1, 2022
This repo contains a collection of permission related Flutter plugins which can be used to request permissions to access device resources in a cross-platform way.

Flutter Permission Plugins Deprecation Notice This repository has been replaced by the Flutter permission_handler plugin and will not longer be mainta

Baseflow 51 Dec 13, 2021
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI 1/2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Fl

Johannes Milke 46 Dec 6, 2022
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI #2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flu

Johannes Milke 45 Dec 15, 2022
Help developers build the most beautiful search bar🍹.

fsearch Help developers build the most beautiful search bar ?? . [FSearch] provides developers with a one-stop search bar construction service. Suppor

Fliggy Mobile 70 Oct 28, 2022
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Ionicfirebaseapp 3.7k Jan 1, 2023
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Ionicfirebaseapp 3.7k Jan 3, 2023
A customizable Flutter library that provides a circular context menu

Flutter Pie Menu ?? A customizable Flutter library that provides a circular context menu similar to Pinterest's. Usage Wrap the widget that will react

Raşit Ayaz 14 Jan 4, 2023
Bringing back contex.read and context.watch for riverpod

This package brings back the context extensions for riverpod that were discontinued in version 1.0.0. To read any provider, do context.read(myProvider

Kilian Schulte 2 Sep 28, 2022
The easiest way to use navigation, context less and useful methods.

Starlight Utils The easiest way to use navigation, context less and useful methods. Features Name Status Context Less Navigation Service ✅ Context Les

Ye Myo Aung 5 Jul 10, 2022
Easy nav - A simple wrapper around flutter navigator, dialogs and snackbar to do those things without context

EasyNav Just a simple wrapper around flutter navigator, dialogs and snackbar to

Abdul Shakoor 2 Feb 26, 2022