plokmij / contextions

A Flutter package that adds extension methods on BuildContext for easy access to Navigator, Theme, and MediaQuery functions.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contextions

Contextions is a Flutter package which makes use of extension methods on BuildContext to easily access Navigator functions, theme functions, and other BuildContext-based functions. This package enhances convenience and readability in Flutter app development.

Features

Navigation

Easily navigate to new pages and manage navigation stack:

context.to(YourPage());
context.navigateAndReplace(YourPage());
context.pop();

Theme and MediaQuery

Access theme data and media query properties directly from BuildContext:

ThemeData theme = context.theme;
TextTheme textTheme = context.textTheme;
Size screenSize = context.screenSize;
double screenHeight = context.screenHeight;
double screenWidth = context.screenWidth;

Snackbar

Show snackbar messages with a single line of code:

context.showSnackbar('Message');

Dialog

Display dialogs with custom content and actions:

context.showDialogX(
  AlertDialog(
    title: Text('Dialog Title'),
    content: Text('Dialog Content'),
    actions: [
      TextButton(
        onPressed: () => context.pop(),
        child: Text('OK'),
      ),
    ],
  ),
);

Drawer

Open and close the drawer:

context.openDrawer();
context.closeDrawer();

Modal Bottom Sheet

Show a modal bottom sheet:

context.showModalBottomSheetX(
  Container(
    child: Text('Bottom Sheet Content'),
  ),
);

Bottom Sheet

Show a customizable bottom sheet:

context.showBottomSheetX(
  builder: (BuildContext context) => Container(
    child: Text('Custom Bottom Sheet Content'),
  ),
);

Search

Show a search interface:

context.showSearchX(
  delegate: CustomSearchDelegate(),
);

Dialog with Custom Content and Actions

Show a dialog with custom content and actions:

context.showDialogXY(
  title: 'Custom Dialog Title',
  content: 'Custom Dialog Content',
  actions: [
    TextButton(
      onPressed: () => context.pop(),
      child: Text('OK'),
    ),
  ],
);

Keyboard Visibility

Check if the keyboard is visible:

bool isKeyboardVisible = context.isKeyboardVisible;

Screen Orientation

Check if the screen is in landscape or portrait mode:

bool isLandscape = context.isLandscape;
bool isPortrait = context.isPortrait;

Example

Here's a basic example demonstrating the usage of contextions:

import 'package:flutter/material.dart';
import 'package:contextions/context_extensions.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Context Extensions Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            context.showSnackbar('Hello from Context Extensions!');
          },
          child: Text('Show Snackbar'),
        ),
      ),
    );
  }
}

void main() {
  runApp(MaterialApp(
    home: MyWidget(),
  ));
}

About

A Flutter package that adds extension methods on BuildContext for easy access to Navigator, Theme, and MediaQuery functions.

https://pub.dev/packages/contextions

License:MIT License


Languages

Language:C++ 35.0%Language:Dart 29.7%Language:CMake 28.6%Language:Swift 2.5%Language:C 2.1%Language:HTML 1.8%Language:Kotlin 0.2%Language:Objective-C 0.1%