我正在创建一个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();
}
}
在之前的Flutter版本中你可以使用String来实现但是现在你需要把它放在Uri.parse(YOUR_URL)