【发布时间】:2021-06-25 20:02:26
【问题描述】:
我想在我的 Flutter 应用 Select Picture 屏幕中加载 assets 文件夹中的所有图像。当用户选择和图像时,它将在另一个屏幕中占用一半空间。所以它与我们手机中的常规编辑图像功能非常相似。
这是用户选择图片后我想要的。
我已成功将所有图像添加到名为画廊的屏幕:
我就是这样做的:
import 'package:flutter/material.dart';
import 'package:flutter_app/src/components/ImageDetails.dart';
List<ImageDetails> _images = [
ImageDetails(
imagePath: 'assets/images/hut.png',
title: 'Hutt',
),
ImageDetails(
imagePath: 'assets/images/scenary.png',
title: 'Scenary',
),
ImageDetails(
imagePath: 'assets/images/menu.png',
title: 'Menu Bar',
),
];
class ImageSelection extends StatefulWidget {
@override
_ImageSelectionState createState() => _ImageSelectionState();
}
class _ImageSelectionState extends State<ImageSelection> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.lightBlueAccent,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(
height: 40,
),
Text(
'Gallery',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w600,
color: Colors.white,
),
textAlign: TextAlign.center,
),
SizedBox(
height: 40,
),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 30,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
return RawMaterialButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(
imagePath: _images[index].imagePath,
title: _images[index].title,
index: index,
),
),
);
},
child: Hero(
tag: 'logo$index',
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
image: DecorationImage(
image: AssetImage(_images[index].imagePath),
fit: BoxFit.cover,
),
),
),
),
);
},
itemCount: _images.length,
),
),
)
],
),
),
);
}
}
class ImageDetails {
final String imagePath;
final String title;
ImageDetails({
@required this.imagePath,
@required this.title,
});
}
但我想动态执行此操作,因此如果我在资产中添加新图像,应用程序将自动显示图像。并在选择图像时将占据画布页面中显示的空间下方?
【问题讨论】:
标签: flutter