flutter - 颤振:获取画廊图像以显示在刷卡中
问题描述
实际上,我正在构建滑动图库应用程序,其中刷卡用于显示图像,然后向左或向右滑动以分别删除或保留图像。我面临的问题是显示在刷卡上的图像是资产图像,但现在我想显示图库的图像(意味着当应用程序运行时,移动图库的图像显示在该刷卡上)。如何获取图库图像并在刷卡上显示以执行功能。我希望你能理解我的问题并期待我的解决方案,:) 谢谢我的代码:
**Code**
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:swipe_cards/swipe_cards.dart';
void main() {
runApp(SwipeGallery());
}
class SwipeGallery extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Swipe Gallery Items',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(
title: 'My New Home Page',
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<SwipeItem> _swipeItems = <SwipeItem>[];
MatchEngine _matchEngine;
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
List<String> _names = [
'assets/images/image_1.jpeg',
'assets/images/image_2.jpeg',
'assets/images/image_3.jpeg',
'assets/images/image_4.jpeg',
'assets/images/image_6.jpeg',
];
@override
void initState() {
for (int i = 0; i < _names.length; i++) {
_swipeItems.add(SwipeItem(
content: Content(
text: _names[i],
),
likeAction: () {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Liked ${_names[i]}"),
duration: Duration(milliseconds: 500),
));
},
nopeAction: () {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Nope ${_names[i]}"),
duration: Duration(milliseconds: 500),
));
},
superlikeAction: () {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Superliked ${_names[i]}"),
duration: Duration(milliseconds: 500),
));
}));
}
_matchEngine = MatchEngine(swipeItems: _swipeItems);
super.initState();
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
child: Column(
children: [
Container(
height: size.height * 0.8,
child: SwipeCards(
matchEngine: _matchEngine,
itemBuilder: (BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.white,
child: Image.asset(
'${_names[index]}',
) //image show here
);
},
onStackFinished: () {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Stack Finished"),
duration: Duration(milliseconds: 500),
));
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.orange)),
onPressed: () {
_matchEngine.currentItem?.nope();
},
child: Text("Nope")),
ElevatedButton(
onPressed: () {
_matchEngine.currentItem?.superLike();
},
child: Text("Superlike")),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.green)),
onPressed: () {
_matchEngine.currentItem?.like();
},
child: Text("Like"))
],
)
],
),
),
);
}
}
class Content {
final String text;
Content({this.text});
}
解决方案
推荐阅读
- typo3 - Extbase 删除控制器/存储库中的重复对象
- postgresql - PostgreSQL 导出表 .csv 作为当前日期
- javascript - 使用数据库的元素来更新猫鼬中的元素?
- react-native - React Native 慢速工作流程中的样式
- javascript - 查找 foo.prototype instanceof bar 所在的所有对象
- javascript - 当指定文本在页面上时,Jquery用户脚本单击单选按钮
- node.js - Mongoose:带有 null 的 ObjectID 数组
- c# - Expression.SwitchCase 匹配问题
- c# - 防止属性被序列化为 XML 的未记录方法
- c - c 中的文件 i/o 和缓冲区操作