From b86945a2dac3fe4e09da7d92ace689dbf8368fcd Mon Sep 17 00:00:00 2001 From: vignesh Date: Thu, 23 Jun 2022 01:09:23 +0530 Subject: [PATCH] 25 add photos design completed --- openclosenew/lib/24_addphotos.dart | 93 +++++++---------- openclosenew/lib/25-addphotos1.dart | 144 +++++++++++++++++++------- openclosenew/lib/26-PhotoListing.dart | 43 ++++++++ openclosenew/pubspec.yaml | 2 +- 4 files changed, 187 insertions(+), 95 deletions(-) create mode 100644 openclosenew/lib/26-PhotoListing.dart diff --git a/openclosenew/lib/24_addphotos.dart b/openclosenew/lib/24_addphotos.dart index 0b789c6..57d96f8 100644 --- a/openclosenew/lib/24_addphotos.dart +++ b/openclosenew/lib/24_addphotos.dart @@ -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 { - 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 { 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, + ), + ) + ], + ), + ), + ), ), ], ), diff --git a/openclosenew/lib/25-addphotos1.dart b/openclosenew/lib/25-addphotos1.dart index e7b24e6..26758c2 100644 --- a/openclosenew/lib/25-addphotos1.dart +++ b/openclosenew/lib/25-addphotos1.dart @@ -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 { + bool uploading = false; + double val = 0; + + List _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(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 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; + }); + } } } diff --git a/openclosenew/lib/26-PhotoListing.dart b/openclosenew/lib/26-PhotoListing.dart new file mode 100644 index 0000000..7f78a69 --- /dev/null +++ b/openclosenew/lib/26-PhotoListing.dart @@ -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 { + @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), + ); + }), + ); + }, + ), + ); + } +} diff --git a/openclosenew/pubspec.yaml b/openclosenew/pubspec.yaml index d2687a8..b5a3e2a 100644 --- a/openclosenew/pubspec.yaml +++ b/openclosenew/pubspec.yaml @@ -42,7 +42,7 @@ dependencies: get: ^4.5.1 smooth_page_indicator: ^1.0.0+2 image_picker: ^0.8.5+3 - +