我正在使用颤振开发健身应用程序。我正在尝试将 Fatsecret API 用于食品和食谱数据库。
我一般是 flutter 和 API 的新手(以前作为初级 android 开发人员,只使用过 firebase)。现在我被困在为 fatsecret API 生成 OAuth 签名。
签名生成的Fatsecret文档,但我不明白。
这是我的代码
import 'dart:convert';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
import 'package:random_string/random_string.dart';
import 'package:sortedmap/sortedmap.dart';
// FatSecret API
class FsApiService {
/// I used these tuts for reference
// https://blog.dantup.com/2017/01/simplest-dart-code-to-post-a-tweet-
// using-oauth/
// http://platform.fatsecret.com/api/Default.aspx?screen=rapiauth
// https://github.com/EugeneHoran/Android-FatSecret-REST-API
// /sf/ask/3485829091/
// request-with-url-encoded-body-in-flutter
//https://groups.google.com/a/dartlang.org/forum/#!topic/cloud/Ci1gFhYBSDQ
// /sf/ask/2023712491/
// signature
static const API_KEY = 'c8f3e40ed0634f5e99919eb944892b17';
static const SHARED_SECRET = 'e8a682cd53094edb9d09090245371ba5';
static const APP_METHOD = 'POST'; …Run Code Online (Sandbox Code Playgroud) 我有一个包含名称、id、卡路里等属性的 Food 对象。通过一系列屏幕,用户填充食物对象属性。
完成后,用户可以按下提交按钮,这将调用商店中的 addFood 方法。
问题是,将食物上传到服务器后,我想根据响应弹出屏幕或在吐司中显示错误消息。我只是不知道该怎么做。
以下是我的代码(仅重要部分): FoodDetailStore.dart
class FoodDetailStore = _FoodDetailStore with _$FoodDetailStore;
abstract class _FoodDetailStore with Store {
Repository _repository;
Food _food;
@observable
String msg = '';
// ... Other Observables and actions
@action
addFood(bool toAdd) {
if (toAdd) {
_repository.addFood(food).then((docId) {
if (docId != null) {
// need to pop the screen
}
}).catchError((e) {
// show error to the user.
// I tried this, but it didn't work
msg = 'there was an error with …Run Code Online (Sandbox Code Playgroud)