portal 1.0.0+3

  • Readme
  • Changelog
  • Example
  • Installing
  • new64

portal #

A flutter plugin to build a widget outside of it's current tree. Similar to React Portals.

image

Thanks to @TahaTesser here

Demo #

https://rive-app.github.io/portal/

Example #

import 'package:flutter/material.dart';

import 'package:portal/portal.dart';

void main() => runApp(MyApp());

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

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final _provider = PortalProvider.of(context);
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: const Text('React Portal Example'),
      ),
      body: ListView.separated(
        itemCount: 500,
        separatorBuilder: (_, index) =>
            Container(height: 2, color: Colors.grey),
        itemBuilder: (_, index) {
          final _key = ValueKey(index);

          return Builder(
            builder: (context) => ListTile(
              title: Text('Test Portal: $index'),
              onTap: () {
                final _portal = ReactPortal(
                    key: _key,
                    builder: (_) => Card(
                          elevation: 5,
                          child: InkWell(
                            onTap: () {
                              _provider.removeKey(_key);
                            },
                            child: Container(
                              width: 200,
                              child: Column(
                                children: <Widget>[
                                  ListTile(
                                    title: Text('Info about the list item..'),
                                    subtitle: Text(index.toString()),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ));
                _portal.show(context);
              },
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.visibility),
        onPressed: () {
          final _key = ValueKey('popup');
          final _portal = ReactPortal(
              key: _key,
              alignment: Alignment.center,
              width: 200,
              height: 500,
              builder: (_) => Card(
                    elevation: 20.0,
                    child: Container(
                      child: Stack(
                        children: <Widget>[
                          Positioned.fill(
                            child: Column(
                              children: <Widget>[
                                ListTile(
                                  title: Text('Popu Up Card'),
                                  subtitle: Text('Sub List Example'),
                                ),
                                Expanded(
                                  child: ListView.builder(
                                    itemCount: 100,
                                    itemBuilder: (_, index) => ListTile(
                                      title: Text(index.toString()),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                          Positioned(
                            right: 0,
                            top: 0,
                            child: IconButton(
                              icon: Icon(Icons.close),
                              onPressed: () {
                                _provider.removeKey(_key);
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                  ));
          _portal.show(context);
        },
      ),
    );
  }
}

0.0.1 #

  • TODO: Describe initial release.

example/README.md

portal_example #

Demonstrates how to use the portal plugin.

Example #

import 'package:flutter/material.dart';

import 'package:portal/portal.dart';

void main() => runApp(MyApp());

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

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final _provider = PortalProvider.of(context);
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: const Text('React Portal Example'),
      ),
      body: ListView.separated(
        itemCount: 500,
        separatorBuilder: (_, index) =>
            Container(height: 2, color: Colors.grey),
        itemBuilder: (_, index) {
          final _key = ValueKey(index);

          return Builder(
            builder: (context) => ListTile(
              title: Text('Test Portal: $index'),
              onTap: () {
                final _portal = ReactPortal(
                    key: _key,
                    builder: (_) => Card(
                          elevation: 5,
                          child: InkWell(
                            onTap: () {
                              _provider.removeKey(_key);
                            },
                            child: Container(
                              width: 200,
                              child: Column(
                                children: <Widget>[
                                  ListTile(
                                    title: Text('Info about the list item..'),
                                    subtitle: Text(index.toString()),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ));
                _portal.show(context);
              },
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.visibility),
        onPressed: () {
          final _key = ValueKey('popup');
          final _portal = ReactPortal(
              key: _key,
              alignment: Alignment.center,
              width: 200,
              height: 500,
              builder: (_) => Card(
                    elevation: 20.0,
                    child: Container(
                      child: Stack(
                        children: <Widget>[
                          Positioned.fill(
                            child: Column(
                              children: <Widget>[
                                ListTile(
                                  title: Text('Popu Up Card'),
                                  subtitle: Text('Sub List Example'),
                                ),
                                Expanded(
                                  child: ListView.builder(
                                    itemCount: 100,
                                    itemBuilder: (_, index) => ListTile(
                                      title: Text(index.toString()),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                          Positioned(
                            right: 0,
                            top: 0,
                            child: IconButton(
                              icon: Icon(Icons.close),
                              onPressed: () {
                                _provider.removeKey(_key);
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                  ));
          _portal.show(context);
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  portal: ^1.0.0+3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:portal/portal.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test