Coder Social home page Coder Social logo

morristech / build_context Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pedromassango/build_context

0.0 1.0 0.0 108 KB

Access most used properties in your BuildContext instance.

Home Page: https://pub.dev/packages/build_context

License: MIT License

Kotlin 3.85% Swift 3.73% Objective-C 0.34% Dart 92.07%

build_context's Introduction

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

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()

Install

Add it in your pubspec.yaml:

dependencies:
  build_context: ^2.0.4

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

build_context's People

Contributors

pedromassango avatar nilsreichardt avatar kmartins avatar victoruvarov avatar vasilich6107 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.