flutter_phoenix 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

Flutter Phoenix #

Easily restart your application from scratch, losing any previous state.

Usage #

Wrap you App widget in the Phoenix widget.

void main() {
  runApp(
    Phoenix(
      child: App(),
    ),
  );
}

Call the rebirth static method when you want to restart your application (rebuild the entire widget tree from scratch).

Phoenix.rebirth(context);

Disclaimer :

Phoenix restarts your application at the application level, rebuilding your application widget tree from scratch, losing any previous state.

Phoenix does not fully restart your application process at the OS level.

Use cases #

Here is a non-exhaustive list of use cases where Phoenix can help :

  • restart the app after a logout
  • restart the app after a failed app initialization process
  • restart the app after a specific event in the app occurs
  • ...

Installation #

Dependency #

Add the package as a dependency in your pubspec.yaml file.

dependencies:
  flutter_phoenix: "^0.1.0"

Import #

Import the package in your code file.

import 'package:flutter_phoenix/flutter_phoenix.dart';

License #

Flutter Phoenix is released under the MIT License

Credit #

This package is an extract of @rrousselGit answer on this stackoverflow post

About us #

We are a french mobile design and development team.

Website : https://www.mobiten.com

Changelog #

All notable changes to this project will be documented in this file.

[0.1.0] - 2020-01-08 #

[0.0.1] - 2019-12-29 #

  • Initial release

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart';

void main() {
  runApp(
    /// 1. Wrap your App widget in the Phoenix widget
    Phoenix(
      child: App(),
    ),
  );
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light(),
      home: const SplashScreen(),
    );
  }
}

class SplashScreen extends StatefulWidget {
  const SplashScreen();

  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();

    simulateInitialDataLoading();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(
              'Initial Screen',
              style: TextStyle(color: Colors.white, fontSize: 34, fontWeight: FontWeight.w700),
            ),
          ],
        ),
      ),
    );
  }

  Future<Timer> simulateInitialDataLoading() async {
    return Timer(
      const Duration(seconds: 2),
          () => Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => const MainScreen(),
        ),
      ),
    );
  }
}

class MainScreen extends StatelessWidget {
  const MainScreen();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          height: double.infinity,
          padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 48.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                'Flutter Phoenix',
                style: TextStyle(fontSize: 34, fontWeight: FontWeight.w700),
              ),
              const SizedBox(height: 24),
              Text(
                'The Phoenix widget enables you to rebuild your widget tree from scratch, losing any state.'
                '\n\nIt basically rebuild your whole application.'
                '\n\nUsage is fairly simple :'
                '\n\n1. Wrap your root App widget in the Phoenix widget'
                '\n\n2. Call Phoenix.rebirth(context); when you want to rebuild your application',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w400, height: 1.5),
              ),
              const Spacer(),
              SizedBox(
                width: double.infinity,
                height: 48.0,
                child: FlatButton(
                  color: Colors.red,
                  textColor: Colors.white,
                  child: const Text('Phoenix.rebirth(context);'),
                  /// 2. Call Phoenix.rebirth(context) to rebuild your app
                  onPressed: () => Phoenix.rebirth(context),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_phoenix: ^0.1.0

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_phoenix/flutter_phoenix.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
86
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]
93
Learn more about scoring.

We analyzed this package on Apr 6, 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/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

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
pedantic ^1.7.0