154 lines
4.7 KiB
Dart
154 lines
4.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:dotted_border/dotted_border.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:openclosenew/26-PhotoListing.dart';
|
|
|
|
import 'FontFamily.dart';
|
|
import 'colors.dart';
|
|
import 'fontsize.dart';
|
|
|
|
class addphotos1 extends StatefulWidget {
|
|
addphotos1({Key? key}) : super(key: key);
|
|
final state = _addphotos1State();
|
|
@override
|
|
State<addphotos1> createState() => state;
|
|
}
|
|
|
|
class _addphotos1State extends State<addphotos1> {
|
|
bool uploading = false;
|
|
double val = 0;
|
|
|
|
List<File> _image = [];
|
|
final picker = ImagePicker();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
elevation: 1,
|
|
backgroundColor: White,
|
|
iconTheme: IconThemeData(color: DarkGray),
|
|
title: Text(
|
|
'Add Photos',
|
|
style: TextStyle(
|
|
fontFamily: Font,
|
|
fontStyle: FontStyle.normal,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: HeadText,
|
|
color: DarkGray,
|
|
),
|
|
),
|
|
actions: [
|
|
MaterialButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
uploading = true;
|
|
});
|
|
uploadFile().whenComplete(() => Navigator.of(context)
|
|
.push(MaterialPageRoute(builder: (_) => HomePage())));
|
|
},
|
|
child: Text(
|
|
'upload',
|
|
style: TextStyle(color: DarkGray),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
body: SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(10),
|
|
),
|
|
),
|
|
padding: EdgeInsets.all(4),
|
|
margin: EdgeInsets.only(left: 10, right: 10, top: 40),
|
|
child: GridView.builder(
|
|
itemCount: _image.length + 1,
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
crossAxisSpacing: 10,
|
|
),
|
|
itemBuilder: (context, index) {
|
|
return index == 0
|
|
? Center(
|
|
child: InkWell(
|
|
onTap: () => !uploading ? chooseImage() : null,
|
|
child: DottedBorder(
|
|
dashPattern: [5, 5, 5, 5],
|
|
color: primaryColor,
|
|
padding: EdgeInsets.all(5),
|
|
radius: Radius.circular(6),
|
|
child: Container(
|
|
height: 100,
|
|
width: 100,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Image(
|
|
image: AssetImage(
|
|
'assets/images/gallery-icon.png'),
|
|
color: primaryColor,
|
|
width: 30,
|
|
height: 30,
|
|
),
|
|
SizedBox(width: 10),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
margin: EdgeInsets.all(3),
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: FileImage(_image[index - 1]),
|
|
fit: BoxFit.cover),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
chooseImage() async {
|
|
final pickedFile = await picker.getImage(source: ImageSource.gallery);
|
|
setState(() {
|
|
_image.add(File(pickedFile!.path));
|
|
});
|
|
if (pickedFile!.path == null) retrieveLostData();
|
|
}
|
|
|
|
Future<void> retrieveLostData() async {
|
|
final LostData response = await picker.getLostData();
|
|
if (response.isEmpty) {
|
|
return;
|
|
}
|
|
if (response.file != null) {
|
|
setState(() {
|
|
_image.add(File(response.file!.path));
|
|
});
|
|
} else {
|
|
print(response.file);
|
|
}
|
|
}
|
|
|
|
Future uploadFile() async {
|
|
int i = 1;
|
|
|
|
for (var img in _image) {
|
|
setState(() {
|
|
val = i / _image.length;
|
|
});
|
|
}
|
|
}
|
|
}
|