在getx颤动中,获取字符串不是RxString子类型

lc8prwob  于 2022-10-09  发布在  Android
关注(0)|答案(0)|浏览(75)

我正在构建一个简单的报价应用程序,但当我点击getQuote按钮时,它给我以下错误。

  • 未处理的异常:类型‘字符串’不是类型‘Rx字符串’的子类型*

代码

...rest code
 child: Column(
            children: [
              Obx(
                () => Text(
                  quoteController.quote.toString(),
                  style: const TextStyle(color: Colors.white, fontSize: 45),
                ),
              ),
              ElevatedButton(
                  onPressed: () {
                    quoteController.getQuote();
                  },
                  child: const Text("Get Quote"))
            ],
          ),

...rest code
import 'dart:convert';

import 'package:get/get.dart';
import 'package:http/http.dart' as http;

class QuoteController extends GetxController {
  RxString quote = "".obs;
  getQuote() async {
    var response = await http.get(Uri.parse("https://api.quotable.io/random"));
    quote = jsonDecode(response.body)['content'] as RxString;
  }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题