小编Emj*_*y23的帖子

Flutter 屏幕条件渲染

我试图在应用程序打开时实现屏幕的有条件显示。

在main.dart中

return Materialapp(
  ...
  home: WelcomePage()
  ...
);
Run Code Online (Sandbox Code Playgroud)

在WelcomePage.dart中

isLoggedin() async {
  prefs = await SharedPreferences.getInstance();
  if (prefs.getString('username') == null) {
    Navigator.of(context).pushAndRemoveUntil(
      MaterialPageRoute(builder: (BuildContext context) => LoginPage()),
      (Route<dynamic> route) => false);
  }
}
Run Code Online (Sandbox Code Playgroud)

问题: - 用户将打开应用程序,在启动屏幕后,将WelcomePage screen立即显示 ,然后将用户重定向到Login screen

这段代码满足了我的需要,也是我真正想要的。我想要的是,WelcomePage screen如果用户在应用程序中没有保存的首选项,应用程序将不会显示 ,而是有一段代码检查应用程序是否会显示Login screenWelcomePage screen

更新

首先,我真的很感谢给出的答案。这两者都有帮助,但我认为另一个答案就是我正在考虑的答案。但我这样做是这样的:

主程序.dart

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();

  SharedPreferences prefs = await SharedPreferences.getInstance();

  _username = prefs.getString("username");
  ...
} 

return Materialapp(
  ...
  home: _username == null …
Run Code Online (Sandbox Code Playgroud)

authentication dart flutter

2
推荐指数
1
解决办法
1993
查看次数

Codeigniter在此服务器上找不到请求的URL

我正在学习Codeigniter,但无法解决遇到的问题。

  • 当用户访问时localhost/reservation/,系统将显示login.php
  • 当用户单击登录按钮时,系统应将用户重定向到系统将显示的另一个视图book.php

一个很好的解释是非常赞赏。

视图

<form class="" method="POST"> 
   <div>
       <button class="btn btn-primary" name="login">Login  </button>
   </div>
</form> 
Run Code Online (Sandbox Code Playgroud)

如您所见,我没有包括用户名和密码输入字段以缩短代码。

控制者

class Reservation extends CI_Controller {
public function _construct()
{
    parent::__construct(;
    $this->load->helper("url");
}

public function index()
{
    if(...some condition...){
        redirect('book');
    }
    $this->load->view('login');
}

public function book(){
    $this->load->view('book');
}
}
Run Code Online (Sandbox Code Playgroud)

我缩短了代码,删除了不必要的代码(以我的观点),以使其更短并直接。

路线

$route['book'] = 'reservation/book';
$route['default_controller'] = 'reservation';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Run Code Online (Sandbox Code Playgroud)

.htaccess

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>
Run Code Online (Sandbox Code Playgroud)

php codeigniter-3

1
推荐指数
1
解决办法
4359
查看次数

标签 统计

authentication ×1

codeigniter-3 ×1

dart ×1

flutter ×1

php ×1