我正在开发新闻应用程序,在某些情况下,有照片库,我需要在故事结尾处上传这些照片,但是我很难在函数之间传递数据并在轮播中检索它们
_getFotos(_id)和loadFotos负责带来数据,并且在类ImageCarousel和Widget构建(BuildContext上下文)中,我安装了旋转木马的整个范围,它正在工作,只需要保持动态并检查是否存在新闻中的图片(如果有的话)或安装轮播。如何兑换数据并使照片动态化?
打印轮播https://i.imgur.com/glISVp4.png
import 'dart:async';
import 'package:news/localization/MyLocalizations.dart';
import 'package:news/util/date_util.dart';
import 'package:news/util/functions.dart';
import 'package:share/share.dart';
import "package:http/http.dart" as http;
import "dart:convert";
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter_html/flutter_html.dart';
const requestNotice = "${url}api/v1/noticias/fotos/";
class DetailPage extends StatelessWidget{
final Completer<WebViewController> _controller = Completer<WebViewController>();
var _img;
var _video_id;
var _title;
var _date;
var _description;
var _link;
var _category;
var _origin;
var img;
var _id;
var _status;
DetailPage(this._img,this._video_id,this._title,this._date,this._description,this._category,this._link,this._origin,this._id, this._status);
MyLocalizations strl;
@override
Widget build(BuildContext context) {
strl = MyLocalizations.of(context);
// Chama a função das fotos e passa o id da notícia
_getFotos(_id);
return new Scaffold(
appBar: new AppBar(
title: new Text(_category),
actions: <Widget>[
IconButton(
icon: Icon(Icons.share),
onPressed: () {
shareNotice();
},
color: Colors.white,
)
],
),
);
}
// Várias funções aqui
_getFotos(id) async {
loadFotos(id);
var fotos = await this.loadFotos(id);
print(fotos);
return fotos;
}
Future shareNotice() async {
await Share.share("$_title:\n$_link");
}
Future<String>loadFotos(id) async {
http.Response response = await http.get(requestNotice + (id));
var fotos = json.decode(response.body);
return fotos;
}
}
class ImageCarousel extends StatefulWidget {
_ImageCarouselState createState() => new _ImageCarouselState();
}
class _ImageCarouselState extends State<ImageCarousel> with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;
initState() {
super.initState();
controller = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = new Tween(begin: 0.0, end: 18.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.forward();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new Container(
padding: EdgeInsets.all(20.0),
height: 200.0,
child: Carousel(
boxFit: BoxFit.cover,
images: [
AssetImage('assets/1.jpeg'),
AssetImage('assets/2.jpeg'),
AssetImage('assets/3.jpeg'),
AssetImage('assets/4.jpeg'),
],
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds:2000),
)
)
);
}
dispose() {
controller.dispose();
super.dispose();
}
}