flutter_statusbarcolor 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 96

flutter_statusbarcolor

pub package

A package can help you to change your flutter app's statusbar's color or navigationbar's color programmatically.

Getting Started

Installation

Add this to your pubspec.yaml (or create it):

dependencies:
  flutter_statusbarcolor: any

Then run the flutter tooling:

flutter packages get

Example

// change the status bar color to material color [green-400].
try {
  await FlutterStatusbarcolor.setStatusBarColor(Colors.green[400]);
  if (useWhiteForeground(Colors.green[400])) {
    FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
  } else {
    FlutterStatusbarcolor.setStatusBarWhiteForeground(false);
  }
} on PlatformException catch (e) {
  print(e);
}

// change the navigation bar color to material color [orange-200].
try {
  await FlutterStatusbarcolor.setNavigationBarColor(Colors.orange[200]);
  if (useWhiteForeground(Colors.orange[200]) {
    FlutterStatusbarcolor.setNavigationBarWhiteForeground(true);
  } else {
    FlutterStatusbarcolor.setNavigationBarWhiteForeground(false);
  }
} on PlatformException catch (e) {
  print(e);
}

preview

Details in example/ folder.

Api level minimum requirement

  • android

    • setStatusBarColor (5.0)
    • setStatusBarWhiteForeground (6.0)
    • setNavigationBarColor (5.0)
    • setNavigationBarWhiteForeground (8.0)
  • ios

    • setStatusBarColor (7+)
    • setStatusBarWhiteForeground (7+)

Note that

  • If ios build does not work, please send issues or pull requests.

Changelog

[0.1.1]

  • Fix ios build.

[0.1.0]

  • Add setStatusBarWhiteForeground to set statusbar content color.
  • Add setNavigationBarWhiteForeground to set navigationbar content color.
  • Add useWhiteForeground to know the background is fit with white content.

[0.0.4]

  • Upgrade to dart2.

[0.0.3]

  • Try to fix ios build again.

[0.0.2]

  • Try to fix ios build.

[0.0.1+1]

  • Format code.

[0.0.1]

  • Initial release.

example/lib/main.dart

import 'dart:math';

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Color randomStatusColor = Colors.black;
  Color randomNavigationColor = Colors.black;

  changeStatusColor(Color color) async {
    try {
      await FlutterStatusbarcolor.setStatusBarColor(color);
      if (useWhiteForeground(color)) {
        FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
        FlutterStatusbarcolor.setNavigationBarWhiteForeground(true);
      } else {
        FlutterStatusbarcolor.setStatusBarWhiteForeground(false);
        FlutterStatusbarcolor.setNavigationBarWhiteForeground(false);
      }
    } on PlatformException catch (e) {
      debugPrint(e.toString());
    }
  }

  changeNavigationColor(Color color) async {
    try {
      await FlutterStatusbarcolor.setNavigationBarColor(color);
    } on PlatformException catch (e) {
      debugPrint(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: Text('Flutter statusbar color plugin example'),
            bottom: TabBar(
              tabs: <Widget>[
                Tab(text: 'Statusbar'),
                Tab(text: 'Navigationbar(android only)')
              ],
            ),
          ),
          body: TabBarView(
            children: <Widget>[
              Column(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  FlatButton(
                    onPressed: () => changeStatusColor(Colors.transparent),
                    child: Text('Transparent'),
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () {
                      Color color = Colors.amberAccent;
                      changeStatusColor(color);
                    },
                    child: Text('amber-accent'),
                    color: Colors.amberAccent,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () => changeStatusColor(Colors.tealAccent),
                    child: Text('teal-accent'),
                    color: Colors.tealAccent,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        FlutterStatusbarcolor.setStatusBarWhiteForeground(true),
                    child: Text(
                      'light foreground',
                      style: TextStyle(color: Colors.white),
                    ),
                    color: Colors.black,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        FlutterStatusbarcolor.setStatusBarWhiteForeground(
                            false),
                    child: Text('dark foreground'),
                    color: Colors.white,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () {
                      Random rnd = Random();
                      Color color = Color.fromARGB(
                        255,
                        rnd.nextInt(255),
                        rnd.nextInt(255),
                        rnd.nextInt(255),
                      );
                      changeStatusColor(color);
                      setState(() => randomStatusColor = color);
                    },
                    child: Text(
                      'Random color',
                      style: TextStyle(
                        color: useWhiteForeground(randomStatusColor)
                            ? Colors.white
                            : Colors.black,
                      ),
                    ),
                    color: randomStatusColor,
                  ),
                ],
              ),
              Column(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  FlatButton(
                    onPressed: () => changeNavigationColor(Colors.green[400]),
                    child: Text('Green-400'),
                    color: Colors.green[400],
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        changeNavigationColor(Colors.lightBlue[100]),
                    child: Text('LightBlue-100'),
                    color: Colors.lightBlue[100],
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        changeNavigationColor(Colors.cyanAccent[200]),
                    child: Text('CyanAccent-200'),
                    color: Colors.cyanAccent[200],
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        FlutterStatusbarcolor.setNavigationBarWhiteForeground(
                            true),
                    child: Text(
                      'light foreground',
                      style: TextStyle(color: Colors.white),
                    ),
                    color: Colors.black,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () =>
                        FlutterStatusbarcolor.setNavigationBarWhiteForeground(
                            false),
                    child: Text('dark foreground'),
                    color: Colors.white,
                  ),
                  Padding(padding: const EdgeInsets.all(10.0)),
                  FlatButton(
                    onPressed: () {
                      Random rnd = Random();
                      Color color = Color.fromARGB(
                        255,
                        rnd.nextInt(255),
                        rnd.nextInt(255),
                        rnd.nextInt(255),
                      );
                      setState(() => randomNavigationColor = color);
                      changeNavigationColor(color);
                    },
                    child: Text(
                      'Random color',
                      style: TextStyle(
                        color: useWhiteForeground(randomNavigationColor)
                            ? Colors.white
                            : Colors.black,
                      ),
                    ),
                    color: randomNavigationColor,
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_statusbarcolor: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
  
Version Uploaded Documentation Archive
0.1.1 Oct 13, 2018 Go to the documentation of flutter_statusbarcolor 0.1.1 Download flutter_statusbarcolor 0.1.1 archive
0.1.0 Oct 10, 2018 Go to the documentation of flutter_statusbarcolor 0.1.0 Download flutter_statusbarcolor 0.1.0 archive
0.0.4 Aug 9, 2018 Go to the documentation of flutter_statusbarcolor 0.0.4 Download flutter_statusbarcolor 0.0.4 archive
0.0.3 Mar 15, 2018 Go to the documentation of flutter_statusbarcolor 0.0.3 Download flutter_statusbarcolor 0.0.3 archive
0.0.2 Mar 14, 2018 Go to the documentation of flutter_statusbarcolor 0.0.2 Download flutter_statusbarcolor 0.0.2 archive
0.0.1+1 Mar 11, 2018 Go to the documentation of flutter_statusbarcolor 0.0.1+1 Download flutter_statusbarcolor 0.0.1+1 archive
0.0.1 Feb 18, 2018 Go to the documentation of flutter_statusbarcolor 0.0.1 Download flutter_statusbarcolor 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
91
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]
96
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8