25 add photos design completed
This commit is contained in:
parent
cab829ecc2
commit
b86945a2da
@ -1,9 +1,5 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:dotted_border/dotted_border.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 '25-addphotos1.dart';
|
||||||
import 'FontFamily.dart';
|
import 'FontFamily.dart';
|
||||||
@ -18,19 +14,6 @@ class addphotos extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _addphtosState extends State<addphotos> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -79,47 +62,43 @@ class _addphtosState extends State<addphotos> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () => pickImage(),
|
onTap: () {
|
||||||
child: image != null
|
Navigator.push(context,
|
||||||
? Image.file(
|
MaterialPageRoute(builder: (_) => addphotos1()));
|
||||||
image!,
|
},
|
||||||
width: 330,
|
child: DottedBorder(
|
||||||
height: 100,
|
dashPattern: [5, 5, 5, 5],
|
||||||
fit: BoxFit.cover,
|
color: primaryColor,
|
||||||
)
|
padding: EdgeInsets.all(5),
|
||||||
: DottedBorder(
|
radius: Radius.circular(6),
|
||||||
dashPattern: [5, 5, 5, 5],
|
child: Container(
|
||||||
color: primaryColor,
|
height: 100,
|
||||||
padding: EdgeInsets.all(5),
|
width: 330,
|
||||||
radius: Radius.circular(6),
|
child: Row(
|
||||||
child: Container(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
height: 100,
|
children: [
|
||||||
width: 330,
|
Image(
|
||||||
child: Row(
|
image:
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
AssetImage('assets/images/gallery-icon.png'),
|
||||||
children: [
|
color: primaryColor,
|
||||||
Image(
|
width: 30,
|
||||||
image: AssetImage(
|
height: 30,
|
||||||
'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,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(width: 10),
|
||||||
|
Text(
|
||||||
|
'Upload Photos',
|
||||||
|
style: TextStyle(
|
||||||
|
fontFamily: Font,
|
||||||
|
fontStyle: FontStyle.normal,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: HeadText,
|
||||||
|
color: primaryColor,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'FontFamily.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'colors.dart';
|
import 'package:openclosenew/26-PhotoListing.dart';
|
||||||
import 'fontsize.dart';
|
import 'package:path/path.dart' as Path;
|
||||||
|
|
||||||
class addphotos1 extends StatefulWidget {
|
class addphotos1 extends StatefulWidget {
|
||||||
const addphotos1({Key? key}) : super(key: key);
|
const addphotos1({Key? key}) : super(key: key);
|
||||||
@ -11,43 +13,111 @@ class addphotos1 extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _addphotos1State extends State<addphotos1> {
|
class _addphotos1State extends State<addphotos1> {
|
||||||
|
bool uploading = false;
|
||||||
|
double val = 0;
|
||||||
|
|
||||||
|
List<File> _image = [];
|
||||||
|
final picker = ImagePicker();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: SafeArea(
|
appBar: AppBar(
|
||||||
child: Padding(
|
title: Text('Add Photos'),
|
||||||
padding: const EdgeInsets.only(left: 20, right: 15, top: 10),
|
actions: [
|
||||||
child: Column(
|
MaterialButton(
|
||||||
children: [
|
onPressed: () {
|
||||||
Row(
|
setState(() {
|
||||||
children: [
|
uploading = true;
|
||||||
InkWell(
|
});
|
||||||
onTap: () {
|
uploadFile().whenComplete(() => Navigator.of(context)
|
||||||
Navigator.pop(context);
|
.push(MaterialPageRoute(builder: (_) => HomePage())));
|
||||||
},
|
},
|
||||||
child: Icon(
|
child: Text(
|
||||||
Icons.arrow_back,
|
'upload',
|
||||||
color: DarkGray,
|
style: TextStyle(color: Colors.white),
|
||||||
size: 24,
|
))
|
||||||
),
|
],
|
||||||
),
|
|
||||||
SizedBox(width: 20),
|
|
||||||
Text(
|
|
||||||
'Add Photos',
|
|
||||||
style: TextStyle(
|
|
||||||
fontFamily: Font,
|
|
||||||
fontStyle: FontStyle.normal,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: HeadText,
|
|
||||||
color: DarkGray,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
openclosenew/lib/26-PhotoListing.dart
Normal file
43
openclosenew/lib/26-PhotoListing.dart
Normal 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),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user