画像ピッカーを使用して画像をアップロードし、別のページに表示する方法について質問があります。このコードでは、5 つの画像をアップロードしていますが、その 5 つのアップロードされた画像を別のページに表示する方法がわかりません。画像アップロード用のモデルを作成しました。質問を理解してください。私はこの時点で非常に立ち往生しています。あなたは私の一日を作ることができます。
これが私が試したコードです。あなたの助けに感謝します。
import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tudo/src/modules/bsp_signup/bsp_signup_common_model.dart';
import 'package:tudo/src/modules/bsp_signup/business_profile/business_profile_page.dart';
import 'package:tudo/src/styles/colors.dart';
import 'package:tudo/src/utils/navigation_helper.dart';
class BspLicensedSignupPage extends StatefulWidget {
static const String routeName = "/bspLicensedSignup";
final BspSignupCommonModel bspSignupCommonModel;
BspLicensedSignupPage({
Key key,
@required this.bspSignupCommonModel,
}) : super(key: key);
@override
_BspLicensedSignupPageState createState() => _BspLicensedSignupPageState();
}
class _BspLicensedSignupPageState extends State<BspLicensedSignupPage> {
List<Object> images = List<Object>();
Future<File> _imageFile;
@override
void initState() {
super.initState();
debugPrint(
'BSP SIGNUP DATA: ${widget.bspSignupCommonModel.businessLegalAddress}');
setState(() {
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
});
}
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
int radioValue = -1;
File _image;
Future<File> licenceimage;
Future<File> profilepicture;
picklicensepicture(ImageSource source) {
setState(() {
licenceimage = ImagePicker.pickImage(source: source);
});
}
pickprofilepicture(ImageSource source) {
setState(() {
profilepicture = ImagePicker.pickImage(source: source);
});
}
Map<String, dynamic> bspsignupdata = new Map<String, dynamic>();
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
});
}
@override
Widget _buildbusinesslicensepicture() {
return GridView.count(
shrinkWrap: true,
crossAxisCount: 5,
childAspectRatio: 1,
children: List.generate(images.length, (index) {
if (images[index] is ImageUploadModel) {
ImageUploadModel uploadModel = images[index];
return Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Image.file(
uploadModel.imageFile,
width: 300,
height: 300,
),
Positioned(
right: 5,
top: 5,
child: InkWell(
child: Icon(
Icons.remove_circle,
size: 20,
color: Colors.red,
),
onTap: () {
setState(() {
images.replaceRange(index, index + 1, ['Add Image']);
});
},
),
),
],
),
);
} else {
return Card(
child: IconButton(
icon: Icon(Icons.add),
onPressed: () {
_onAddImageClick(index);
},
),
);
}
}),
);
}
Future _onAddImageClick(int index) async {
setState(() {
_imageFile = ImagePicker.pickImage(source: ImageSource.gallery);
getFileImage(index);
});
}
void getFileImage(int index) async {
_imageFile.then((file) async {
setState(() {
ImageUploadModel imageUpload = new ImageUploadModel();
imageUpload.isUploaded = false;
imageUpload.uploading = false;
imageUpload.imageFile = file;
imageUpload.imageUrl = '';
images.replaceRange(index, index + 1, [imageUpload]);
});
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("BSP Licensed Signup"),
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
NavigationHelper.navigatetoBack(context);
},
),
),
bottomNavigationBar: Container(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new FlatButton.icon(
icon: Icon(FontAwesomeIcons.arrowCircleRight),
label: Text('Next'),
color: colorStyles["primary"],
textColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 30),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7),
),
onPressed: () async {
if (_formKey.currentState.validate()) {
BspSignupCommonModel model = widget.bspSignupCommonModel;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BusinessProfilePage(bspSignupCommonModel: model),
),
);
}
},
),
],
),
),
body: Container(
height: double.infinity,
width: double.infinity,
child: Stack(
children: <Widget>[
// Background(),
SingleChildScrollView(
child: SafeArea(
top: false,
bottom: false,
child: Form(
autovalidate: true,
key: _formKey,
child: Scrollbar(
child: SingleChildScrollView(
dragStartBehavior: DragStartBehavior.down,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: new Container(
margin: EdgeInsets.fromLTRB(30, 30, 30, 0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 10,
),
_buildbusinesslicensepicture(),
SizedBox(
height: 20,
),
],
),
),
),
),
),
),
),
],
),
),
);
}
}
class ImageUploadModel {
bool isUploaded;
bool uploading;
File imageFile;
String imageUrl;
ImageUploadModel({
this.isUploaded,
this.uploading,
this.imageFile,
this.imageUrl,
});
}