context_extensions 2.0.0 copy "context_extensions: ^2.0.0" to clipboard
context_extensions: ^2.0.0 copied to clipboard

Various extensions on BuildContext to access inherited widget's state

example/main.dart

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

main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MainPage(),
    );
  }
}

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  OverlayEntry? _overlayEntry;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: <Widget>[
          ElevatedButton(
            onPressed: () {
              if (_overlayEntry == null) {
                _overlayEntry = context.addOverlay((context) {
                  return Align(
                    alignment: AlignmentDirectional.bottomStart,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Text('overlay'),
                    ),
                  );
                });
              } else {
                _overlayEntry!.remove();
                _overlayEntry = null;
              }
            },
            child: Text('add/remove overlay'),
          ),
        ],
      ),
    );
  }
}
4
likes
150
points
29
downloads

Publisher

verified publisheraligator.ir

Weekly Downloads

Various extensions on BuildContext to access inherited widget's state

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on context_extensions