Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

How to add some functionality in my Flutter app?

I am developing a password manager application and want to add some functionality in it but I don't know how to do it.

I have added 2 option in my app settings i.e.

  1. Auto lock when not in use: where I am giving user so select some time like when user doesn't interact with application then my app would be automatically lock after that time, I have added 5 options from which user can select 1. off 2. 30 sec 3. 1 min 4. 5 min 5. 30 min and I have a widget for lockscreen that should be call to lock the application.

  2. Activate Auto locking: when user enabled this option, app will lock in 5 seconds after screen goes off.

How can I achieve this functionality in my application?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could do something like:

void main() {
  runApp(Root());
}

class Root extends StatefulWidget {

  bool _isLocked = false;

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      home: showLockScreen ? LockScreenWidget() : OpenScreenWidget();
    );
  }

  void triggerLock() {
    setState(() {
       isLocked = !isLocked;
    });
   }
}

This could be your starter code, but it requires a Timer that you need to implement. Whenever you want to lock the screen, you can just call triggerLock().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...