context_extensions 0.3.0+1 copy "context_extensions: ^0.3.0+1" to clipboard
context_extensions: ^0.3.0+1 copied to clipboard

outdated

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>[
          FlatButton(
            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
40
pub points
26%
popularity

Publisher

verified publisheraligator.ir

Various extensions on BuildContext to access inherited widget's state

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on context_extensions