【发布时间】: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