如何在Flutter中使用会话用户?

时间:2018-10-03 06:26:16

标签: http dart flutter

我一直在尝试使用dart在flutter中使用户登录并向http注册。我想以某种方式使用户使用会话或cookie停留在应用程序中。有人在尝试吗?

2 个答案:

答案 0 :(得分:1)

签出requests

  • 到目前为止,它使用shared_preferences并不是存储安全数据(会话ID等)的最佳实践(从安全角度考虑)Issue #1

pubspec.yaml

dependencies:
  requests: ^1.0.0

用法:

import 'package:requests/requests.dart';

// ...

// this will persist cookies
await Requests.post("https://example.com/api/v1/login", body: {"username":"...", "password":"..."} ); 

// this will re-use the persisted cookies
dynamic data = await Requests.get("https://example.com/api/v1/stuff", json: true); 

答案 1 :(得分:1)

如果要查找用户会话而不是HTTP会话,请签出flutter_session

这真的很容易实现,甚至在导航后也可以在页面中保留。