Skip to content

Commit

Permalink
added image picker in add event through 0x0.st
Browse files Browse the repository at this point in the history
  • Loading branch information
KejariwalAyush committed Nov 23, 2020
1 parent 63036d7 commit d2ca95c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
65 changes: 57 additions & 8 deletions iter_aio/lib/pages/events/events_form.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:intl/intl.dart';
import 'package:iteraio/Utilities/Theme.dart';
import 'package:iteraio/Utilities/global_var.dart';
import 'dart:io';

class EventsForm extends StatefulWidget {
@override
Expand Down Expand Up @@ -43,9 +45,11 @@ class _EventsFormState extends State<EventsForm> {
child: RaisedButton.icon(
icon: Icon(Icons.publish),
label: Text('Publish'),
onPressed: () {
onPressed: () async {
if (_fbKey.currentState.saveAndValidate()) {
var x = _fbKey.currentState.value;
if (x['imgUrl'] != null)
x['imgUrl'] = await uploadImg(x['imgUrl'][0]);
print(x);
try {
events.add(x);
Expand Down Expand Up @@ -88,7 +92,7 @@ class _EventsFormState extends State<EventsForm> {
return FormBuilder(
key: _fbKey,
initialValue: {
'eventDate': DateTime.now(),
// 'eventDate': DateTime.now(),
'time': DateTime.now(),
},
child: SingleChildScrollView(
Expand Down Expand Up @@ -134,14 +138,25 @@ class _EventsFormState extends State<EventsForm> {
decoration: InputDecoration(labelText: "Detailed Description"),
autocorrect: true,
),
FormBuilderTextField(

/// add Image then upload it and get link
FormBuilderImagePicker(
attribute: 'imgUrl',
decoration: InputDecoration(labelText: "Image Url (Optional)"),
validators: [
FormBuilderValidators.url(),
],
autocorrect: true,
decoration: const InputDecoration(
labelText: 'Images',
),
maxImages: 1,
iconColor: Colors.grey,
// onSaved: uploadImg,
),
// FormBuilderTextField(
// attribute: 'imgUrl',
// decoration: InputDecoration(labelText: "Image Url (Optional)"),
// validators: [
// FormBuilderValidators.url(),
// ],
// autocorrect: true,
// ),
FormBuilderTextField(
attribute: 'link',
decoration:
Expand Down Expand Up @@ -287,4 +302,38 @@ class _EventsFormState extends State<EventsForm> {
),
);
}

uploadImg(value) async {
File img = value;
var url = 'https://0x0.st';
var resp;
var formData = FormData.fromMap({
"file": await MultipartFile.fromFile(img.path, filename: 'my'),
});
resp = await Dio().post(
url,
data: formData,
onSendProgress: (int sent, int total) {
// showDialog(
// context: context,
// barrierDismissible: false,
// builder: (BuildContext context) => AlertDialog(
// title: Text('Uploading'),
// content: Text(
// '$sent/$total(${(sent / total).ceil() * 100}%)'),
// actions: [
// if (sent == total)
// FlatButton(
// child: Text('Okay'),
// onPressed: () => Navigator.pop(context),
// )
// ],
// ),
// );
print("$sent $total");
},
);
print(resp);
return resp.toString().trim();
}
}
7 changes: 7 additions & 0 deletions iter_aio/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.10"
draggable_scrollbar:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions iter_aio/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
fluttertoast: ^4.0.0
html: null
http: ^0.12.2
dio: ^3.0.10
splashscreen: null
line_awesome_icons: ^1.0.4+2
draggable_scrollbar: ^0.0.4
Expand Down

0 comments on commit d2ca95c

Please sign in to comment.