Home > OS >  How do i create a rounded search bar in flutter that also shows the recent searches from the search
How do i create a rounded search bar in flutter that also shows the recent searches from the search

Time:03-25

I have been wanting to find a solution to create a rounded search bar in flutter which also shows the list of recent searches underneath it. How is it possible to create the previous widget?

CodePudding user response:

Using the package below, you can save the information you want to the device memory and then withdraw it from there (username, password, search history, etc.). The sample code is in the document.

https://pub.dev/packages/shared_preferences

like this:

    void handleRememberMe(bool? value) {
    _isChecked = value!;
    SharedPreferences.getInstance().then(
      (prefs) {
        prefs.setBool("remember_me", value);
        prefs.setString('userName', userNameController.text);
        prefs.setString('password', passwordController.text);
      },
    );
    setState(() {
      _isChecked = value;
    });
  }

  void loadUserEmailPassword() async {
    try {
      SharedPreferences _prefs = await SharedPreferences.getInstance();
      var _email = _prefs.getString("userName") ?? "";
      var password = _prefs.getString("password") ?? "";
      var _remeberMe = _prefs.getBool("remember_me") ?? false;
      if (_remeberMe) {
        setState(() {
          _isChecked = true;
        });
        userNameController.text = _email;
        passwordController.text = password;
      } else {
        userNameController.text = "";
        passwordController.text = "";
        setState(() {
          _isChecked = false;
        });
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  }
  • Related