【发布时间】:2019-09-10 04:51:08
【问题描述】:
我想制作这种类型的图像选择器,当我点击加号时,它会在我选择适合此容器的图像时打开图像选择器。
这是我尝试过的一些代码。
在这段代码中,我使用了平面按钮,它将拾取图像并将其显示在平面按钮下。但我想要像我在图片中提到的那样输出。 5 种不同的图片上传器。
import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class BusinessProfilePage extends StatefulWidget {
@override
_BusinessProfilePageState createState() => _BusinessProfilePageState();
}
class _BusinessProfilePageState extends State<BusinessProfilePage> {
Future<File> profilepicture;
bool aggreeandaccept = false;
bool accepttudo = false;
pickprofilepicture(ImageSource source) {
setState(() {
profilepicture = ImagePicker.pickImage(source: source);
});
}
Widget _buildbusinessprofilepicture() {
return new FormField(
builder: (FormFieldState state) {
return FlatButton.icon(
icon: Icon(Icons.image),
label: Text('Business Profile Picture'),
//color: Colors.white,
textColor: Colors.black54,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
onPressed: () {
pickprofilepicture(ImageSource.gallery);
},
);
},
);
}
Widget _buildprofileimage() {
return FutureBuilder<File>(
future: profilepicture,
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) {
return Image.file(
snapshot.data,
width: 100,
height: 100,
);
} else if (snapshot.error != null) {
return const Text(
'Error Picking Image',
textAlign: TextAlign.center,
);
} else {
return const Text(
'No Image Selected',
textAlign: TextAlign.center,
);
}
},
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("BusinessProfile"),
),
body: Container(
height: double.infinity,
width: double.infinity,
child: Stack(
children: <Widget>[
SingleChildScrollView(
child: SafeArea(
top: false,
bottom: false,
child: Form(
child: Scrollbar(
child: SingleChildScrollView(
dragStartBehavior: DragStartBehavior.down,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: new Container(
margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildbusinessprofilepicture(),
_buildprofileimage(),
],
),
),
),
),
),
),
),
],
),
),
);
}
}
【问题讨论】: