- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前有一个旋转木马,可以在其中添加和删除图像,但是问题是我可以在旋转木马的最后一张照片之后添加图像。
同样,我可以按顺序删除最后一张照片。
如何根据轮播中的用户位置选择要删除的图片或在何处添加图片?
我使用两个按钮,一个用于添加图片,另一个用于删除图片,方法是调用特定的方法(一个用于添加的方法,另一个用于删除的方法)。
这是代码
import 'dart:io';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
class ProductCarousel extends StatefulWidget {
@override
_ProductCarouselState createState() => _ProductCarouselState();
}
class ImageConfig {
String source;
String path;
ImageConfig({this.source, this.path});
}
class _ProductCarouselState extends State<ProductCarousel> {
List<ImageConfig> imgList = [
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2016/04/15/08/04/strawberries-1330459_960_720.jpg'),
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2019/12/01/16/56/cookies-4665910_960_720.jpg'),
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2017/05/23/22/36/vegetables-2338824_960_720.jpg')
];
List<Widget> imageSliders;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
imgList.add(ImageConfig(source: "file", path: pickedFile.path));
});
}
Future deleteImage() async {
setState(() {
imgList.removeLast();
});
}
@override
Widget build(BuildContext context) {
imageSliders = imgList
.map(
(item) =>
Container(
child: Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
item.source == "http"
? Image.network(item.path,
fit: BoxFit.cover, width: 1000.0)
: Image.file(File(item.path),
fit: BoxFit.cover, width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(200, 0, 0, 0),
Color.fromARGB(0, 0, 0, 0)
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
),
),
],
)),
),
),
)
.toList();
return Container(
child: Column(
children: <Widget>[
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 2.0,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
pauseAutoPlayOnManualNavigate: true,
pauseAutoPlayOnTouch: true,
scrollDirection: Axis.horizontal),
items: imageSliders,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
padding: EdgeInsets.all(8.0),
splashColor: Colors.tealAccent,
child: Row(
children: <Widget>[
Icon(FontAwesomeIcons.plus),
],
),
onPressed: getImage,
),
FlatButton(
padding: EdgeInsets.all(8.0),
splashColor: Colors.red,
child: Row(
children: <Widget>[
Icon(FontAwesomeIcons.trashAlt),
],
),
onPressed: deleteImage,
),
],
)
],
),
);
}
}
最佳答案
int pageIndex = 0;
onPageChanged
属性添加到CarouselSlider
中:onPageChanged: (index, reason) {
pageIndex = index;
}
getImage()
:Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
//imgList.add(ImageConfig(source: "file", path: pickedFile.path));
if (pageIndex == 0)
imgList.add(ImageConfig(source: "file", path: pickedFile.path));
else
imgList.insert(pageIndex + 1, ImageConfig(source: "file", path: pickedFile.path)); //insert after current image
});
}
deleteImage()
:Future deleteImage() async {
setState(() {
//imgList.removeLast();
imgList.removeAt(pageIndex); //remove current image
});
}
import 'dart:io';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
class ProductCarousel extends StatefulWidget {
@override
_ProductCarouselState createState() => _ProductCarouselState();
}
class ImageConfig {
String source;
String path;
ImageConfig({this.source, this.path});
}
class _ProductCarouselState extends State<ProductCarousel> {
int pageIndex = 0;
List<ImageConfig> imgList = [
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2016/04/15/08/04/strawberries-1330459_960_720.jpg'),
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2019/12/01/16/56/cookies-4665910_960_720.jpg'),
ImageConfig(
source: "http",
path:
'https://cdn.pixabay.com/photo/2017/05/23/22/36/vegetables-2338824_960_720.jpg')
];
List<Widget> imageSliders;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
//imgList.add(ImageConfig(source: "file", path: pickedFile.path));
if (pageIndex == 0)
imgList.add(ImageConfig(source: "file", path: pickedFile.path));
else
imgList.insert(pageIndex + 1, ImageConfig(source: "file", path: pickedFile.path));
});
}
Future deleteImage() async {
setState(() {
//imgList.removeLast();
imgList.removeAt(pageIndex);
});
}
@override
Widget build(BuildContext context) {
imageSliders = imgList
.map(
(item) =>
Container(
child: Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
item.source == "http"
? Image.network(item.path,
fit: BoxFit.cover, width: 1000.0)
: Image.file(File(item.path),
fit: BoxFit.cover, width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(200, 0, 0, 0),
Color.fromARGB(0, 0, 0, 0)
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
),
),
],
)),
),
),
)
.toList();
return Scaffold(
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center ,
children: <Widget>[
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 2.0,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
pauseAutoPlayOnManualNavigate: true,
pauseAutoPlayOnTouch: true,
scrollDirection: Axis.horizontal,
onPageChanged: (index, reason) {
pageIndex = index;
}
),
items: imageSliders,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
padding: EdgeInsets.all(8.0),
splashColor: Colors.tealAccent,
child: Row(
children: <Widget>[
Icon(FontAwesomeIcons.plus),
],
),
onPressed: getImage,
),
FlatButton(
padding: EdgeInsets.all(8.0),
splashColor: Colors.red,
child: Row(
children: <Widget>[
Icon(FontAwesomeIcons.trashAlt),
],
),
onPressed: deleteImage,
),
],
)
],
),
)
);
}
}
关于flutter - Flutter在轮播中添加具有已知位置的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63914909/
我在我的应用程序中使用开源 iCarousel 来实现轮播控件。我使用的轮播类型是 iCarouselTypeRotary 并且图像在这种类型中线性排列。但是,我需要图像像所附图像中的旋转木马一样带来
有人看过像这样的 jQuery 3D 轮播教程吗? http://web.enavu.com/demos/3dcarouselwip/ 没有给出来源,但想知道是否有人有关于如何连续圈出 DIV 并调整
我正在开发一种使用相机自动拍摄照片的软件。我希望用户能够设置照片间隔。我希望它看起来和工作起来像某种轮播。 它应该是这样的: 当我滑动(或用鼠标拖动)时,它应该沿给定方向移动: 所选项目应始终位于中间
抱歉问了个愚蠢的问题。我正在寻找带有按钮的旋转木马。我在 Bootply 上找到了这个模板,它完全符合我的要求。我在开发方面还很陌生。 也许有人可以向我解释如何摆脱侧面滚动效果。我知道我必须向 Jav
我正在寻找一个可以处理表单元素的 jQuery 轮播风格插件。 这是我需要做的。 我有三个表单元素:两个常规文本框和一个文本区域。还有两个按钮,上一个和下一个。 单击下一步按钮时,文本框/文本区域会切
我想构建一个包含两个图像轮播的网页,并且我希望能够将图像从一个轮播拖动到另一个。 我已经有了与 jCarouselLite 一起使用的图像轮播:它使用两个 UL 元素来指定轮播的图像。这工作得很好。
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我有这段代码可以从数据库中获取轮播图片或视频 $stmt = $con->prepare("SELECT * FROM `Main`"); $stmt->execut
我需要做这个 slider ,我找到了一些代码并尝试了,但没有一个完全是 LIKE THIS .bloco03 img {
我的任务是制作 3 张图片的轮播/幻灯片,只能在移动设备上使用。在桌面上,这些图像将显示在 3 列中。有没有一种方法可以自动转换,而无需我创建两个不同的模块并根据屏幕尺寸隐藏/显示一个? 最佳答案 你
我需要在卡片轮播上创建这种效果。我使用 Owl Carousel ,我给了元素框阴影。但我坚持制作不同位置元素的效果,例如 3d 或任何名称。 这是我想做的 http://www.awesomescr
我已经盯着这段相同的代码看了大约 4 个小时,并尝试观看一些不同的教程。问题是 slider 加载,有 3 张幻灯片的空间,但它只显示第一张幻灯片。 所有图像加载良好(在浏览器中验证),但轮播不会更改
我的 carouse/slider 有问题,我已经做到了,上一张和下一张图片每边各占 25%,中央图片占 50% 宽度。问题是我能够更改左右图像的背景,但我似乎无法将相同的颜色应用于中间图像。我已经尝
我想一次放 5 张图片作为页面的背景,即一张图片会显示一小段时间(比如每张一秒钟),然后重复它们。 我想知道有没有办法用 CSS 或 JS 来做到这一点? 预先感谢您的帮助! 最佳答案 这也许就是您正
我正在寻找一个支持触摸、可拖动、响应式 jQuery 滚动条/幻灯片/轮播/ slider ,用于显示水平可滚动项目列表(例如, eshop、最近将照片添加到数据库等)。 它看起来类似于苹果应用程序商
我想要夹层画廊的 Bootstrap 轮播。基本上;我正在拉入所有图像,并且我想要单行三张图像轮播。这是我非常讨厌的一段工作代码;我真的很想让它适用于无限数量的图像。 {% if page.d
大家好,我有这段代码,我一直在为我的网站编写代码。我正在尝试实现一个轮播功能,其中一张图片在另一张图片之后滑动。我遇到的问题是图片不会滑动。这是我的代码在欢迎 Controller 的索引页面中的样子
我正在构建一个简单的轮播,一旦用户水平滚动,事件点就会改变事件状态。但是,当我滚动时,jQuery 左侧位置返回值没有改变: li_left = li.position().left; // this
我正在尝试将文本放在轮播 slider 中的图像下方,但现在文本出现在图像上,而不是下方。 它看起来像这样: 但我希望它看起来像这样: 这是我的代码: final CarouselSlider aut
我在使用 boostrap carousel 时遇到 CSS 问题 我只是想让它更高,我已经尝试了几个 css 但没有任何效果。代码是在这个 jsFiddle 中,http://jsfiddle.ne
我是一名优秀的程序员,十分优秀!