logo

该视频仅会员有权观看

立即开通课程「Flutter 移动端应用开发实践」权限。

¥
199
/ 年

The current user interface displays whether the user is logged in or not. If not logged in, a "not logged in" message is shown; if logged in, it displays information related to the user. The user profile widget needs to be modified using prepared data methods: context.read for an app model and context.watch for an auth model. The watch method listens for changes in the auth model and rebuilds the widget upon changes. A TextButton is provided for login, which when pressed triggers the app model to change the page name attribute to "auth login." Navigation pages are managed accordingly, adding a user login page if app model's config name equals "auth login."

For the user profile, another TextButton is utilized that shows the logged-in user's name from the auth model. An "onPressed" method logs the user out. The user profile widget's build method is simplified by removing the Consumer widget as the necessary data has already been prepared. A conditional check within the Center widget shows the user profile if auth model's isLoggedin is true and displays a "login" button if false.

The user interface reflects the current login state by showing a "please log in" button for non-authenticated users. By modifying navigation in the app router delegate, when the auth model's config name matches "auth login", a new login page is added including a MaterialPage, key, and child for the login. Within the login page's build method, a scaffold with an 'AppBar' and a title "user login" is set up, and a login form (auth login form) is included. Testing this setup shows that pressing the login button on the user page opens the user login page.