flutter_visibility_aware 0.0.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 66

flutter_visibility_aware #

A tiny widget which is aware of its visibility based on https://pub.dev/packages/visibility_detector

Intro #


    // Just wrapper on the widget which wants to handle visible or invisible events. 

    VisibilityAware(
      visibleCallback: () async {
        debugPrint("$this is visible.");
      },
      invisibleCallback: () async {
        debugPrint("$this is invisible.");
      },
      child: Scaffold(
        appBar: AppBar(),
        body: Container(
          color: Colors.white,
          child: Center(
            child: Text(
              "$this",
            ),
          ),
        ),
      ),
    );

Dependencies #

visibility_detector

License #

Copyright 2020 Chris Xinyue Zhao

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.0.2+1] - 2020-06-02 #

  • invisibleCallback is nullable.
  • visibleCallback is required and not nullable.

[0.0.2] - 2020-06-02 #

  • Remove WidgetsBindingObserver support
  • Add analysis_options.yaml
  • Fix warning in main.dart (example)

[0.0.1+1] - 2020-05-31 #

  • Fix homepage in pubspec.lock

[0.0.1] - 2020-05-31 #

  • The initial release.
    • Add VisibilityAware
    • Add example app
    • Setup github, readme etc.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_visibility_aware/flutter_visibility_aware.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      onGenerateRoute: (RouteSettings settings) {
        switch (settings.name) {
          case "/VisibilityAwareStatelessPage":
            return MaterialPageRoute<void>(
              settings: settings,
              fullscreenDialog: true,
              builder: (BuildContext context) => VisibilityAwareStatelessPage(),
            );
          case "/VisibilityAwareStatefulPage":
            return MaterialPageRoute<void>(
              settings: settings,
              fullscreenDialog: true,
              builder: (BuildContext context) => VisibilityAwareStatefulPage(),
            );
          default:
            return MaterialPageRoute<void>(
              settings: settings,
              fullscreenDialog: true,
              builder: (BuildContext context) => SelectionPage(),
            );
        }
      },
    );
  }
}

class SelectionPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return VisibilityAware(
      visibleCallback: () async {
        debugPrint(
            "SelectionPage is visible.");
      },
      invisibleCallback: () async {
        debugPrint(
            "SelectionPage is invisible.");
      },
      child: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              VisibilityAware(
                visibleCallback: () async {
                  debugPrint(
                      "RaisedButton for opening VisibilityAwareStatelessPage is visible.");
                },
                invisibleCallback: () async {
                  debugPrint(
                      "RaisedButton for opening VisibilityAwareStatelessPage is invisible.");
                },
                child: RaisedButton(
                  onPressed: () {
                    Navigator.of(
                      context,
                      rootNavigator: true,
                    ).pushNamed(
                      "/VisibilityAwareStatelessPage",
                    );
                  },
                  child: const Text("A stateless widget page example"),
                ),
              ),
              VisibilityAware(
                visibleCallback: () async {
                  debugPrint(
                      "RaisedButton for opening VisibilityAwareStatefulPage is visible.");
                },
                invisibleCallback: () async {
                  debugPrint(
                      "RaisedButton for opening VisibilityAwareStatefulPage is invisible.");
                },
                child: RaisedButton(
                  onPressed: () {
                    Navigator.of(
                      context,
                      rootNavigator: true,
                    ).pushNamed(
                      "/VisibilityAwareStatefulPage",
                    );
                  },
                  child: const Text("A stateful widget page example"),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class VisibilityAwareStatelessPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return VisibilityAware(
      visibleCallback: () async {
        debugPrint("$this is visible.");
      },
      invisibleCallback: () async {
        debugPrint("$this is invisible.");
      },
      child: Scaffold(
        appBar: AppBar(),
        body: Container(
          color: Colors.white,
          child: Center(
            child: Text(
              "$this",
            ),
          ),
        ),
      ),
    );
  }
}

class VisibilityAwareStatefulPage extends StatefulWidget {
  @override
  _VisibilityAwareStatefulPageState createState() =>
      _VisibilityAwareStatefulPageState();
}

class _VisibilityAwareStatefulPageState
    extends State<VisibilityAwareStatefulPage> {
  @override
  Widget build(BuildContext context) {
    return VisibilityAware(
      visibleCallback: () async {
        debugPrint("$widget is visible.");
      },
      invisibleCallback: () async {
        debugPrint("$widget is invisible.");
      },
      child: Scaffold(
        appBar: AppBar(),
        body: Container(
          color: Colors.white,
          child: Center(
            child: Text(
              "$widget",
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_visibility_aware: ^0.0.2+1

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:flutter_visibility_aware/flutter_visibility_aware.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_visibility_aware that is a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
visibility_detector ^0.1.5 0.1.5
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test