FLUTTER ECOSYSTEM

fuadarradhi/double_back_to_close

앱/경로/화면을 닫기 전에 두 번의 뒤로 가기 버튼을 요청하기 위한 Flutter 패키지입니다.

double_back_to_close 프로젝트 이미지
Stars
2
Forks
0
최근 푸시(UTC)
2021. 4. 14.
프로젝트 상태
활성
Fuad Ar-Radhi GitHub avatar
GITHUB User

Fuad Ar-Radhi ↗

언어DartRubySwiftJavaObjective-C

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개
  • flutter{"sdk":"flutter"}
  • flutter_test개발 의존성{"sdk":"flutter"}

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

double_back_to_close

Flutter package for request double back pressed before close app/route/screen.

Demo

Usage

Wrapping widget with DoubleBack where you want to use double back to close screen or app:

Default (using TOAST)
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DoubleBack(
          message:"Press back again to close",
          child: Home(),
        ),
      ),
  }
}
Default (using TOAST) with optional style
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DoubleBack(
          message:"Press back again to close",
          child: Home(),
        ),
      ),
      // optional style
      textStyle: TextStyle(
        fontSize: 13,
        color: Colors.white,
      ),
      background: Colors.red,
      backgroundRadius: 30,
    );
  }
}
Custom ( using snackbar for example)


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DoubleBack(
        onFirstBackPress: (context) {

          // you can use your custom here
          // change this with your custom action
          final snackBar = SnackBar(content: Text('Press back again to exit'));
          ScaffoldMessenger.of(context).showSnackBar(snackBar);
          // ---

        },

        child: Home(),
      ),
    );
  }
}
with custom delay
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DoubleBack(
          onFirstBackPress: (context) {

            Flushbar(
              title: "Hey User",
              message: "Press back again to exit",
              duration: Duration(seconds: 15), // show 15 second flushbar
            )..show(context);

          },
          child: Home(),
          waitForSecondBackPress: 15, // wait for 15 second for second back pressed
        ),
    );
  }
}
with custom condition

if you want to show message at spesific condition, for example, only show message if pageView at index 0.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // Imagine that you are using materialbottom and only want to close when tabIndex = 0

      home: DoubleBack(
          condition: tabIndex == 0, // only show message when tabIndex=0
          onConditionFail: (){
            setState((){
                tabIndex = 0; // if not 0, set pageview jumptopage 0
            });
          }
          child: Home(),
        ),
    );
  }
}