need_resume 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

Need Resume #

Need Resume is a package to implement onResume, onPause, onReady functionality on a Stateful widget (this is for every screen).

Quick Usage #

Replace State<MyWidget> with ResumableState<MyWidget> and then implement the void onResume(), void onPause(), and/or void onReady() abstract method. Replace Navigator.push() or Navigator.pushNamed() with push() or pushNamed()

Attention #

NeedResume class is now deprecated, replaced with ResumableState<T> abstract class, please see example for detail

Installation #

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

dependencies:
  need_resume: ^1.0.4

Example #

Basic example:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'My Application', home: HomeScreen());
  }
}

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

class HomeScreenState extends ResumableState<HomeScreen> {
  @override
  void onReady() {
    // Implement your code inside here

    print('HomeScreen is ready!');
  }

  @override
  void onResume() {
    // Implement your code inside here

    print('HomeScreen is resumed!');
  }

  @override
  void onPause() {
    // Implement your code inside here

    print('HomeScreen is paused!');
  }

  void goAnotherScreen() {
    // Replace Navigator.push() or Navigator.pushNamed() with push() or pushNamed()

    push(context, MaterialPageRoute(builder: (context) => AnotherScreen()));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Go to Another Screen'),
          onPressed: () {
            goAnotherScreen();
          },
        ),
      ),
    );
  }
}

class AnotherScreen extends StatefulWidget {
  @override
  AnotherScreenState createState() => AnotherScreenState();
}

class AnotherScreenState extends ResumableState<AnotherScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Go Back'),
          onPressed: () {
            goBack();
          },
        ),
      ),
    );
  }

  void goBack() {
    Navigator.pop(context);
  }
}

How about to get data from a screen? Just use resume.data and resume.source:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'My Application', home: HomeScreen());
  }
}

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

class HomeScreenState extends ResumableState<HomeScreen> {
  @override
  void onResume() {
    switch (resume.source) {
      case 'another_screen':
        print('Data from AnotherScreen: ${resume.data}');
        break;
    }
  }

  void goAnotherScreen() {
    push(context, MaterialPageRoute(builder: (context) => AnotherScreen()), 'another_screen');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Go to Another Screen'),
          onPressed: () {
            goAnotherScreen();
          },
        ),
      ),
    );
  }
}

class AnotherScreen extends StatefulWidget {
  @override
  AnotherScreenState createState() => AnotherScreenState();
}

class AnotherScreenState extends ResumableState<AnotherScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Go Back'),
          onPressed: () {
            goBack();
          },
        ),
      ),
    );
  }

  void goBack() {
    Navigator.pop(context, 'Hello!');
  }
}

Changelog #

1.0.4 #

  • Bug fixing on AppLifecycleState case clause

1.0.3+2 #

  • Update test

1.0.3+1 #

  • Update README.md

1.0.3 #

  • Add onPause() and onReady() methods
  • NeedResume class is now deprecated, replaced with ResumableState<T> abstract class, see example for detail

1.0.2 #

  • Simplify onResume implementation
  • Now, all you have to do is just replace Navigator.push() or Navigator.pushNamed() with push() or pushNamed()
  • Add resume.data and resume.source to store data from a screen you have pushed

1.0.1+1 #

  • Update README.md

1.0.1 #

  • Add github link

1.0.0 #

  • Initial release
  • Basic functionality

example/example.dart

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

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

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            title: 'My Application',
            home: HomeScreen()
        );
    }
}

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

class HomeScreenState extends ResumableState<HomeScreen> {
    @override
    void onReady() {
        // Implement your code inside here

        print('HomeScreen is ready!');
    }

    @override
    void onResume() {
        // Implement your code inside here

        print('HomeScreen is resumed!');
    }

    @override
    void onPause() {
        // Implement your code inside here

        print('HomeScreen is paused!');
    }

    void goAnotherScreen() {
        // Replace Navigator.push() or Navigator.pushNamed() with push() or pushNamed()

        push(context, MaterialPageRoute(builder: (context) => AnotherScreen()));
    }

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: Center(
                child: RaisedButton(
                    child: Text('Go to Another Screen'),
                    onPressed: () {
                        goAnotherScreen();
                    },
                ),
            ),
        );
    }
}

class AnotherScreen extends StatefulWidget {
    @override
    AnotherScreenState createState() => AnotherScreenState();
}

class AnotherScreenState extends ResumableState<AnotherScreen> {
    @override
    void onReady() {
        // Implement your code inside here

        print('AnotherScreen is ready!');
    }

    @override
    void onResume() {
        // Implement your code inside here

        print('AnotherScreen is resumed!');
    }

    @override
    void onPause() {
        // Implement your code inside here

        print('AnotherScreen is paused!');
    }

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: Center(
                child: RaisedButton(
                    child: Text('Go Back'),
                    onPressed: () {
                        goBack();
                    },
                ),
            ),
        );
    }

    void goBack() {
        Navigator.pop(context);
    }
}

Use this package as a library

1. Depend on it

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


dependencies:
  need_resume: ^1.0.4

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

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

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

Health suggestions

Format lib/need_resume.dart.

Run flutter format to format lib/need_resume.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