NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import 'dart:io';

import 'package:cliqright/constants/assets.dart';
import 'package:cliqright/constants/colors.dart';
import 'package:cliqright/constants/dimens.dart';
import 'package:cliqright/constants/strings.dart';
import 'package:cliqright/data/network/api_provider.dart';
import 'package:cliqright/data/network/multi_picker_model.dart';
import 'package:cliqright/data/sharedpref/constants/local_storage.dart';
import 'package:cliqright/model/request_model/auth_reuest_model.dart';
import 'package:cliqright/model/request_model/services_reuest_model.dart';
import 'package:cliqright/model/responseModel/add_item.dart';
import 'package:cliqright/ui/edit_item.dart';
import 'package:cliqright/ui/home/main_screen.dart';
import 'package:cliqright/utility/custom_loader.dart';
import 'package:cliqright/utility/dialogs.dart';
import 'package:cliqright/utility/helper_utility.dart';
import 'package:cliqright/utility/helper_widget.dart';
import 'package:cliqright/utility/image_picker.dart';
import 'package:cliqright/widgets/popup_dialog.dart';
import 'package:cliqright/widgets/rasiedButton.dart';
import 'package:cliqright/widgets/rectangular_textfield.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_absolute_path/flutter_absolute_path.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:multi_image_picker/multi_image_picker.dart';

import '../../routes.dart';

class PostItemPage extends StatefulWidget {
@override
_PostItemPageState createState() => _PostItemPageState();
}

class _PostItemPageState extends State<PostItemPage> {
int _dropValue;
bool isChecked;
String _error = 'No Error Dectected';

TextEditingController enterNameController;
TextEditingController addDescController;
TextEditingController priceController;
FocusNode enterNameNode;
FocusNode addDescNode;
FocusNode priceNode;
CustomLoader _customLoader;
AddItemResponseModel addItemResponseModel;
var mulipartImage;
File image;
List<File> _files;
List<Asset> images = <Asset>[];

List<String> listWidget = [];
List<MultiPickerModel> _list = [];
List<MultipartFile> multipart = [];
var selectedValue = "Day";
List<MultiPickerModel> imageList = [];

@override
void initState() {
super.initState();
_list.add(MultiPickerModel("", 10));
enterNameController = TextEditingController();
addDescController = TextEditingController();
priceController = TextEditingController();
enterNameNode = FocusNode();
addDescNode = FocusNode();
priceNode = FocusNode();
_dropValue = 2;
isChecked = false;
}

@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final orientation = MediaQuery.of(context).orientation;
return SafeArea(
child: Scaffold(
backgroundColor: white,
appBar: HelperWidget.appbar(
context: context, title: Strings.postaitem, back: false),
body: Container(
height: HelperUtility.fullheightscreen(context: context),
width: HelperUtility.fullWidthScreen(context: context),
padding: EdgeInsets.symmetric(
horizontal: Dimens.width_20, vertical: Dimens.width_10),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
gap(6),
RectangularTextField(
hint: Strings.enterItemName,
focusNode: enterNameNode,
textController: enterNameController,
width: HelperUtility.fullWidthScreen(context: context),
inputAction: TextInputAction.next,
inputType: TextInputType.text,
maxLine: 1,
),
gap(10),
Container(
height: 100,
child: RectangularTextField(
textController: addDescController,
focusNode: addDescNode,
maxLine: null,
minLine: 4,
hint: Strings.addDescription,
inputType: TextInputType.multiline,
),
),
checkBox(),
gap(6),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: TextFormField(
enabled: isChecked == false ? true : false,
textAlign: TextAlign.center,
textInputAction: TextInputAction.done,
focusNode: priceNode,
controller: priceController,
inputFormatters: [
LengthLimitingTextInputFormatter(6),
FilteringTextInputFormatter.allow(RegExp("[0-9]"))
],
keyboardType: TextInputType.number,
decoration: new InputDecoration(
isDense: true,
filled: true,
hintText: Strings.price,
hintStyle: isChecked == false
? TextStyle(
color: Colors.black,
fontWeight: FontWeight.w300,
fontSize: Dimens.font_15)
: TextStyle(
color: Colors.black38,
fontWeight: FontWeight.w300,
fontSize: Dimens.font_15),
fillColor: Colors.grey.shade200,
labelStyle: HelperUtility.textStyleBold(
color: Colors.grey,
fontsize: Dimens.font_16,
),
contentPadding: const EdgeInsets.only(
top: Dimens.margin_15,
bottom: Dimens.margin_15,
left: Dimens.margin_25,
right: Dimens.margin_15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide.none),
)),
),
),
SizedBox(
width: 20,
),
Expanded(child: _dropdownItems(context)),
],
),
gap(30),
uploadCoverImageText(),
gap(10),
coverImage(),
gap(20),
uploadOtherImageText(),
gap(10),
GridView.builder(
itemCount: _list.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (contet, index) {
return _list[index].index == 10
? _plusIconWidget()
: _imageWidget(_list[index].image, index);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 10,
crossAxisSpacing: 10),
),
gap(15),
postButton(),
gap(6),
],
),
),
),
),
);
}

bool isShow = false;

_imageWidget(String file, int index) {
return Stack(
children: [
Container(
height: 100,
width: 100,
margin: EdgeInsets.all(2),
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 1.0,
spreadRadius: 0.1,
offset: Offset(0.1, 0.1), // shadow direction: bottom right
)
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(18),
child: Image.file(
File(file),
fit: BoxFit.fill,
))),
new Positioned(
top: 7,
right: 14,
child: HelperWidget.getInkwell(
onTap: () {
setState(() {
_list.removeAt(index);
images.removeAt(index);
if (_list.length == 4 && isShow == false) {
_list.add(MultiPickerModel("", 10));
isShow = true;
}
});
},
widget: Container(
decoration: BoxDecoration(
color: Colors.deepOrangeAccent,
borderRadius: BorderRadius.circular(8),
),
child: Icon(
Icons.close,
color: Colors.white,
size: 15,
),
))),
],
);
}

_plusIconWidget() {
return GestureDetector(
onTap: () {
isShow = false;
loadAssets();
},
child: Container(
height: 100,
width: 100,
margin: EdgeInsets.all(2),
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 1.0,
spreadRadius: 0.1,
offset: Offset(0.1, 0.1), // shadow direction: bottom right
)
],
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Image.asset(Assets.plus, height: 40, width: 40),
),
),
);
}

_postItemApi() async {
if (enterNameController.text.isEmpty) {
Fluttertoast.showToast(msg: Strings.itemNAme);
return;
}
if (addDescController.text.isEmpty) {
Fluttertoast.showToast(msg: Strings.addDescription);
return;
}

if (isChecked != true && priceController.text.isEmpty) {
Fluttertoast.showToast(msg: Strings.priceError);
return;
}
if (priceController.text == "0") {
HelperWidget.toast(message: Strings.price0Error);
return;
}
if (image == null) {
HelperWidget.toast(message: Strings.coverImageError);
return;
}
if (image != null) {
mulipartImage =
await MultipartFile.fromFile(image.path, filename: image.path);
}
multipart.clear();
for (int i = 0; i < images.length; i++) {
// multipart.clear();
var path =
await FlutterAbsolutePath.getAbsolutePath(images[i].identifier);
var multipartfile = await MultipartFile.fromFile(path, filename: path);
multipart.add(multipartfile);
}
var requestData = ServicesRequestModel.addItemReuestModel(
color: "red",
image: multipart,
free: isChecked,
frequency: selectedValue,
price: priceController.text.trim(),
description: addDescController.text.trim(),
name: enterNameController.text.trim(),
coverImage: mulipartImage,
);
await APIRepository.addItemApiCall(requestData, context).then((value) => {
if (value != null)
{
addItemResponseModel = value,
HelperWidget.toast(message: addItemResponseModel.message),
HelperUtility.pushAndRemoveUntil(
context: context,
route: Home(
pageIndex: 3,
routeRefrence: LocalStorage.myPostedItemRefrence,
)),
}
});
}

SizedBox gap(double height) => SizedBox(height: height);

Container _dropdownItems(BuildContext context) {
return Container(
padding: EdgeInsets.all(7),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimens.width_15),
color: Colors.grey.shade200),
height: 50,
width: HelperUtility.fullWidthScreen(context: context) * 0.39,
child: isChecked == true
? Container(
height: 50,
padding: EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${selectedValue}",
style: HelperUtility.textStyleBold(
fontsize: 15, color: Colors.black26),
),
Icon(
Icons.keyboard_arrow_down_rounded,
color: Colors.black26,
size: 26,
)
],
),
)
: PopupMenuButton(
onSelected: (value) {
if (value == 1) {
setState(() {
selectedValue = Strings.day;
});
} else if (value == 2) {
setState(() {
selectedValue = Strings.week;
});
} else if (value == 3) {
setState(() {
selectedValue = Strings.month;
});
}
},
icon: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${selectedValue}",
style: HelperUtility.textStyleBold(
fontsize: 15, color: Colors.black54),
),
Icon(
Icons.keyboard_arrow_down_rounded,
size: 26,
)
],
),
offset: Offset(0, 30),
shape: ShapedWidgetBorder(
borderRadius: BorderRadius.circular(10.0), padding: 1.0),
itemBuilder: (BuildContext context) => [
PopupMenuItem(
height: 2,
child: Column(
children: [
Text(
Strings.day,
style: TextStyle(color: Colors.black),
),
Divider(
thickness: 1,
color: Colors.grey[300],
)
],
),
value: 1,
),
PopupMenuItem(
height: 2,
child: Column(
children: [
Text(
Strings.week,
style: TextStyle(color: Colors.black),
),
Divider(
thickness: 1,
color: Colors.grey[300],
)
],
),
value: 2,
),
PopupMenuItem(
height: 2,
child: Center(
child: Padding(
padding: const EdgeInsets.only(
bottom: 7.0,
),
child: Text(
Strings.month,
style: TextStyle(color: Colors.black),
),
),
),
value: 3,
),
],
),
);
}

Widget checkBox() {
return Padding(
padding: EdgeInsets.only(left: 25.0, top: 13.0, bottom: 5.0),
child: Row(
children: [
Theme(
data: ThemeData(unselectedWidgetColor: Colors.deepOrangeAccent),
child: Container(
margin: EdgeInsets.only(right: 4.0),
height: 25,
width: 25,
child: Checkbox(
activeColor: Colors.deepOrangeAccent,
value: isChecked,
onChanged: (newValue) {
priceController.clear();
setState(() {
isChecked = !isChecked;
});
},
),
),
),
Text(
Strings.shareForFree,
style: TextStyle(
color: Colors.deepOrangeAccent,
fontSize: Dimens.font_16,
fontWeight: FontWeight.w400),
),
],
),
);
}

Widget coverImage() {
return ClipRRect(
borderRadius: BorderRadius.circular(Dimens.width_5),
child: InkWell(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Container(
height: HelperUtility.fullheightscreen(context: context) * 0.20,
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(22),
image: image == null
? DecorationImage(
alignment: Alignment.center,
image: AssetImage(Assets.photo),
fit: BoxFit.scaleDown,
)
: DecorationImage(
image: FileImage(image),
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
HelperWidget.getInkwell(
onTap: () {
FocusScope.of(context).unfocus();
showDailog(true);
},
widget: Image.asset(
Assets.cameraWithShadow,
height: 25,
),
)
],
),
),
),
),
);
}

Widget uploadOtherImageText() {
return Padding(
padding: const EdgeInsets.only(left: Dimens.width_18),
child: Text(
Strings.uploadOtherImage,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: Dimens.font_16),
),
);
}

Widget uploadCoverImageText() {
return Padding(
padding: const EdgeInsets.only(left: Dimens.width_18),
child: Text(
Strings.uploadCoverImage,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: Dimens.font_16),
),
);
}

Widget postButton() {
return Center(
child: FractionallySizedBox(
widthFactor: 0.85,
child: ButtonWidget(
onPressed: () {
_postItemApi();
},
textColor: white,
fontsize: Dimens.font_18,
buttonColor: radish,
borderColor: radish,
height: Dimens.height_45,
width: HelperUtility.fullWidthScreen(context: context),
buttonText: Text(Strings.post),
),
),
);
}

Widget grid() {
return Container(
width: HelperUtility.fullWidthScreen(context: context),
padding: EdgeInsets.symmetric(vertical: 2, horizontal: 0),
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 0),
child: GridView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: images.length,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 15,
crossAxisSpacing: 15,
),
itemBuilder: (context, index) {
Asset asset = images[index];
return Container(
margin: EdgeInsets.all(2),
padding: EdgeInsets.all(0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 1.0,
spreadRadius: 0.1,
offset:
Offset(0.1, 0.1), // shadow direction: bottom right
)
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(18),
child: AssetThumb(
asset: asset,
height: 100,
width: 100,
),
),
);
}));
}

void showDailog(bool isSingle) => AlertDialogs.showDialog(
context: context,
widget: Padding(
padding: EdgeInsets.only(
left: Dimens.margin_20,
right: Dimens.margin_20,
bottom: Dimens.margin_10,
top: Dimens.margin_10),
child: Card(
elevation: 10.0,
child: Container(
width: HelperUtility.fullWidthScreen(context: context),
decoration: HelperWidget.decorationBox(
borderWidth: Dimens.radius_1,
cornerRaduis: Dimens.margin_0,
borderColor: Colors.white,
backgroundColor: Colors.white),
padding: EdgeInsets.all(Dimens.margin_15),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Align(
alignment: Alignment.topRight,
child: HelperWidget.getInkwell(
onTap: () {
Navigator.pop(context);
},
widget: Icon(
Icons.cancel,
color: Colors.red,
)),
),
Text(
Strings.choose,
style: HelperUtility.textStyleBold(
color: Colors.black, fontsize: Dimens.font_18),
),
HelperWidget.sizeBox(height: Dimens.width_20),
Row(
children: [
Expanded(
child: InkWell(
onTap: () {
_imagePickGromCamer();
},
child: Container(
child: Column(
children: [
Icon(
Icons.camera_alt,
size: 50.0,
color: Colors.red,
),
Text(
Strings.camera,
style: HelperUtility.textStyle(
color: Colors.black,
fontsize: Dimens.font_14),
),
],
),
),
)),
Expanded(
child: InkWell(
onTap: () {
if (isSingle == true)
_imagePickGallery();
else {
loadAssets();
}
// Navigator.pop(context);
},
child: Container(
child: Column(
children: [
Icon(
Icons.file_copy_rounded,
size: 50.0,
color: Colors.red,
),
Text(
Strings.gallery,
style: HelperUtility.textStyle(
color: Colors.black,
fontsize: Dimens.font_14),
),
],
),
),
)),
],
),
HelperWidget.sizeBox(height: Dimens.width_20),
],
),
),
),
));

void _multipleImagePick() async {
var pickImage = await ImagePick.loadMultipleImages();
File file = File(pickImage);
if (file == null) {
HelperWidget.toast(message: Strings.cancel);
} else {
_cropImage(pickImage.path);
}
}

void _imagePickGromCamer() async {
File file;
var pickedFile = await ImagePick.imgFromCamera();
if (pickedFile != null) file = File(pickedFile.path);
if (file == null) {
HelperWidget.toast(message: Strings.cancel);
} else {
_cropImage(pickedFile.path);
}
}

_cropImage(filePath) async {
File croppedImage = await ImageCropper.cropImage(
sourcePath: filePath,
aspectRatioPresets: [CropAspectRatioPreset.square],
);
Navigator.pop(context);
if (mounted) if (mounted)
setState(() {
image = croppedImage;
});
}

void _imagePickGallery() async {
File file;
var pickedFile = await ImagePick.imgFromGallery();
if (pickedFile != null) file = File(pickedFile.path);
if (file == null) {
HelperWidget.toast(message: Strings.cancel);
} else {
_cropImage(pickedFile.path);
}
}

Future<void> loadAssets() async {
List<Asset> resultList = <Asset>[];
String error = 'No Error Detected';

try {
resultList = await MultiImagePicker.pickImages(
maxImages: 5,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Select Pictures",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
} on Exception catch (e) {
error = e.toString();
}

if (!mounted) return;

setState(() {
images = resultList;
_error = error;
});
if (images != null) {
listWidget.clear();
for (int i = 0; i < resultList.length; i++) {
var file =
await FlutterAbsolutePath.getAbsolutePath(resultList[i].identifier);
//_files.add(File(file));
listWidget.add(file);
}

_list.clear();
for (int i = 0; i < listWidget.length; i++) {
_list.add(MultiPickerModel(listWidget[i], i));
}
if (_list.length < 5) {
_list.add(MultiPickerModel("", 10));
isShow = true;
}
setState(() {});
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.