flutter_system_bars 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

flutter_system_bars (WIP) #

Flutter plugin that helps you create immersive experience for your app by defining margins based on system bars dimensions.

Screenshot

Usage #

This plugin has two main widgets:

SystemBarsInfoProvider #

This widget provides info about system bar heights and if software navigation bar is present to its descendants.

SystemBarsInfoProvider(
  builder: (context, child, systemBarsInfo, orientation) {
    return Center(
      child: Text(systemBarsInfo.navigationBarHeight, 
        textAlign: TextAlign.center, 
        style: TextStyle(color: Colors.white, fontSize: 20)
      ),
    );
  }
);

You have to pass in the builder in which you get SystemBarsInfo object and device Orientation for convenience. The child parameter is optional. You can pass child parameter to SystemBarsInfoProvider constructor and it is not affected by changes in layout.

SystemBarsInfo contains information about system bars:

class SystemBarsInfo {
  final bool hasSoftwareNavigationBar;
  final double navigationBarHeight;
  final double statusBarHeight;
}

SystemBarsMarginBox #

This widgets encapsulates SystemBarsInfoProvider and lets you choose which margins you want to show based on system bars in specified orientations.

SystemBarsMarginBox(
  portraitMargin: true,
  landscapeMargin: false,
  navigationBarMargin: true,
  statusBarMargin: true,
  child: Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text('Content is below',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.white, fontSize: 20)),
        Text('While the app occupies the entire screen.',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.white, fontSize: 20)),
        Text('and above system bars.',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.white, fontSize: 20)),
      ]),
);

SystemBarsMarginBox settings and their default values:

portraitMargin - default: true - specifies if margin is enabled in portrait mode

landscapeMargin - default: false - specifies if margin is enabled in landscape mode

navigationBarMargin - default: true - specifies if margin is enabled for navigation bar

statusBarMargin - default: true - specifies if margin is enabled for status bar

Disclaimer #

Plugin is currently implemented only for Android platform. On iOS it reports system bar heights as 0 and navigation bar as non existent. That is because I am a poor student who doesn´t have money for iPhone and Mac so I can't write iOS implementation. If you want to implement iOS functionality please open a pull request.

0.0.5 #

  • Added basic iOS support.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_system_bars/flutter_system_bars.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      systemNavigationBarColor: Colors.transparent,
    ));

    return MaterialApp(
      home: Scaffold(
        resizeToAvoidBottomPadding: false,
        body: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
              stops: [0.0, 1.0],
              colors: [Color.fromARGB(255, 223, 61, 139), Color.fromARGB(255, 86, 147, 219)],
            ),
          ),
          child: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints viewportConstraints) {
              return SingleChildScrollView(
                child: ConstrainedBox(
                    constraints: BoxConstraints(
                      minHeight: viewportConstraints.maxHeight,
                    ),
                    child: IntrinsicHeight(
                      child: SystemBarsMarginBox(
                          child: Column(
                              crossAxisAlignment: CrossAxisAlignment.stretch,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                            Text('Content is below',
                                textAlign: TextAlign.center,
                                style: TextStyle(color: Colors.white, fontSize: 20)),
                            Text('While the app occupies the entire screen.',
                                textAlign: TextAlign.center,
                                style: TextStyle(color: Colors.white, fontSize: 20)),
                            Text('and above system bars.',
                                textAlign: TextAlign.center,
                                style: TextStyle(color: Colors.white, fontSize: 20)),
                          ])),
                    )),
              );
            },
          ), /*SystemBarsMarginBox(
            portraitMargin: true,
            landscapeMargin: false,
            navigationBarMargin: true,
            statusBarMargin: true,
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('Content is below',
                      textAlign: TextAlign.center,
                      style: TextStyle(color: Colors.white, fontSize: 20)),
                  Text('While the app occupies the entire screen.',
                      textAlign: TextAlign.center,
                      style: TextStyle(color: Colors.white, fontSize: 20)),
                  Text('and above system bars.',
                      textAlign: TextAlign.center,
                      style: TextStyle(color: Colors.white, fontSize: 20)),
                ]),
          ),*/
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_system_bars: ^0.0.5

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_system_bars/flutter_system_bars.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
48
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/flutter_system_bars.dart.

Run flutter format to format lib/flutter_system_bars.dart.

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.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