【问题标题】:Flutter : The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’ [duplicate]Flutter:参数类型“String”不能分配给参数类型“Uri”[重复]
【发布时间】:2021-11-23 10:55:24
【问题描述】:

我正在创建一个 gif 搜索,但是当我必须插入 url 时,我收到以下消息“参数类型‘String’不能分配给参数类型‘Uri’”

我尝试使用的代码是...


import 'dart:convert';

import 'package:flutter/material.dart';

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

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  String _search ='';
  
  int _offset = 0;

  Future<Map>_getGifs() async {
    http.Response response;

    if(_search == nullnull || _search.isEmpty)
      response = await http.get("https://api.giphy.com/v1/gifs/trending?api_key=hyx64ldsiQzZCcFnKzZQZ4mQoTZUSp0L&limit=20&rating=g");
    else 
      response = await http.get("https://api.giphy.com/v1/gifs/search?api_key=$_search&limit=25&offset=$_offset&rating=g&lang=en");

    return json.decode(response.body);


  }
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

【问题讨论】:

    标签: json flutter http dart uri


    【解决方案1】:

    在之前版本的 Flutter 上你可以用 String 来做,但现在你需要把它放在Uri.parse(YOUR_URL)

    【讨论】:

      猜你喜欢
      • 2021-06-27
      • 2021-10-17
      • 2021-06-19
      • 2021-06-30
      • 2021-06-10
      • 1970-01-01
      • 2023-04-05
      • 2021-10-02
      相关资源
      最近更新 更多