25 add photos design completed

This commit is contained in:
vignesh 2022-06-23 01:09:23 +05:30
parent cab829ecc2
commit b86945a2da
4 changed files with 187 additions and 95 deletions

View File

@ -1,9 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import '25-addphotos1.dart';
import 'FontFamily.dart';
@ -18,19 +14,6 @@ class addphotos extends StatefulWidget {
}
class _addphtosState extends State<addphotos> {
File? image;
Future pickImage() async {
try {
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if (image == null) return;
final imageTemporary = File(image.path);
setState(() => this.image = imageTemporary);
} on PlatformException catch (e) {
print('failed to pick image:$e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -79,47 +62,43 @@ class _addphtosState extends State<addphotos> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
InkWell(
onTap: () => pickImage(),
child: image != null
? Image.file(
image!,
width: 330,
height: 100,
fit: BoxFit.cover,
)
: DottedBorder(
dashPattern: [5, 5, 5, 5],
color: primaryColor,
padding: EdgeInsets.all(5),
radius: Radius.circular(6),
child: Container(
height: 100,
width: 330,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
image: AssetImage(
'assets/images/gallery-icon.png'),
color: primaryColor,
width: 30,
height: 30,
),
SizedBox(width: 10),
Text(
'Upload Photos',
style: TextStyle(
fontFamily: Font,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: HeadText,
color: primaryColor,
),
)
],
),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (_) => addphotos1()));
},
child: DottedBorder(
dashPattern: [5, 5, 5, 5],
color: primaryColor,
padding: EdgeInsets.all(5),
radius: Radius.circular(6),
child: Container(
height: 100,
width: 330,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
image:
AssetImage('assets/images/gallery-icon.png'),
color: primaryColor,
width: 30,
height: 30,
),
),
SizedBox(width: 10),
Text(
'Upload Photos',
style: TextStyle(
fontFamily: Font,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: HeadText,
color: primaryColor,
),
)
],
),
),
),
),
],
),

View File

@ -1,7 +1,9 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'FontFamily.dart';
import 'colors.dart';
import 'fontsize.dart';
import 'package:image_picker/image_picker.dart';
import 'package:openclosenew/26-PhotoListing.dart';
import 'package:path/path.dart' as Path;
class addphotos1 extends StatefulWidget {
const addphotos1({Key? key}) : super(key: key);
@ -11,43 +13,111 @@ class addphotos1 extends StatefulWidget {
}
class _addphotos1State extends State<addphotos1> {
bool uploading = false;
double val = 0;
List<File> _image = [];
final picker = ImagePicker();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.only(left: 20, right: 15, top: 10),
child: Column(
children: [
Row(
children: [
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Icon(
Icons.arrow_back,
color: DarkGray,
size: 24,
),
),
SizedBox(width: 20),
Text(
'Add Photos',
style: TextStyle(
fontFamily: Font,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w500,
fontSize: HeadText,
color: DarkGray,
),
),
],
),
],
),
appBar: AppBar(
title: Text('Add Photos'),
actions: [
MaterialButton(
onPressed: () {
setState(() {
uploading = true;
});
uploadFile().whenComplete(() => Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => HomePage())));
},
child: Text(
'upload',
style: TextStyle(color: Colors.white),
))
],
),
),
);
body: Stack(
children: [
Container(
padding: EdgeInsets.all(4),
child: GridView.builder(
itemCount: _image.length + 1,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (context, index) {
return index == 0
? Center(
child: IconButton(
icon: Icon(Icons.add),
onPressed: () =>
!uploading ? chooseImage() : null),
)
: Container(
margin: EdgeInsets.all(3),
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(_image[index - 1]),
fit: BoxFit.cover)),
);
}),
),
uploading
? Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text(
'uploading...',
style: TextStyle(fontSize: 20),
),
),
SizedBox(
height: 10,
),
CircularProgressIndicator(
value: val,
valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
)
],
))
: Container(),
],
));
}
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;
});
}
}
}

View File

@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import '25-addphotos1.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Home Page')),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => addphotos1()));
},
),
body: StreamBuilder(
builder: (context, snapshot) {
return !snapshot.hasData
? Center(
child: CircularProgressIndicator(),
)
: Container(
padding: EdgeInsets.all(4),
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.all(3),
);
}),
);
},
),
);
}
}

View File

@ -42,7 +42,7 @@ dependencies:
get: ^4.5.1
smooth_page_indicator: ^1.0.0+2
image_picker: ^0.8.5+3