need_resume 1.0.3+1 copy "need_resume: ^1.0.3+1" to clipboard
need_resume: ^1.0.3+1 copied to clipboard

outdated

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

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);
    }
}
34
likes
0
pub points
93%
popularity

Publisher

verified publisherfaruq.id

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on need_resume