Guest User

Untitled

a guest
May 27th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:onlinecity/component/TextField/inputField.dart';
  3. import 'package:onlinecity/component/Button/roundedButton.dart';
  4. import 'package:onlinecity/component/Button/textButton.dart';
  5. import 'style.dart';
  6. import 'package:onlinecity/theme/style.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:cloud_firestore/cloud_firestore.dart';
  9. import 'package:image_picker/image_picker.dart';
  10. import 'dart:async';
  11. import 'dart:io';
  12.  
  13. class AddOfferScreen extends StatefulWidget {
  14.  
  15.  
  16. @override
  17. AddOfferScreenState createState() => new AddOfferScreenState();
  18. }
  19.  
  20. class AddOfferScreenState extends State<AddOfferScreen> {
  21. final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
  22. final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  23. bool _autovalidate = false;
  24. String _productTitle;
  25. String _category;
  26. String _contactNumber;
  27. Future<File> _imageFile;
  28.  
  29. void _onImageButtonPressed(ImageSource source) {
  30. setState(() {
  31. _imageFile = ImagePicker.pickImage(source: source);
  32. });
  33. }
  34.  
  35. _onPressed() {
  36. print("button clicked");
  37. }
  38.  
  39. void showInSnackBar(String value) {
  40. _scaffoldKey.currentState
  41. .showSnackBar(new SnackBar(content: new Text(value)));
  42. }
  43.  
  44. bool _handleSubmitted() {
  45. final FormState form = _formKey.currentState;
  46. if (form.validate()) {
  47. form.save();
  48. return true;
  49. }
  50. return false;
  51. }
  52. void validateAndSubmit() async{
  53. if (_handleSubmitted()){
  54. try {
  55. Firestore.instance.collection('todos').document().setData({"productTitle":_productTitle,"category":_category,"contactNumber":_contactNumber});
  56.  
  57. }
  58. catch (e){
  59. print('Error: $e');
  60. }
  61. }
  62.  
  63. }
  64.  
  65. void _showaddphoto(){
  66. AlertDialog dialog = new AlertDialog(
  67. actions: <Widget>[
  68. new IconButton(icon: new Icon(Icons.camera_alt), onPressed: () => _onImageButtonPressed(ImageSource.camera),
  69. tooltip: 'Take a Photo'),
  70. new IconButton(icon: new Icon(Icons.sd_storage), onPressed: () => _onImageButtonPressed(ImageSource.gallery),
  71. tooltip: 'Pick Image from gallery')
  72.  
  73. ],
  74. );
  75. showDialog(context: context,child: dialog);
  76.  
  77. }
  78.  
  79. @override
  80. Widget build(BuildContext context) {
  81. // TODO: implement build
  82. Size screenSize = MediaQuery.of(context).size;
  83. //print(context.widget.toString());
  84. return new Scaffold(
  85. key: _scaffoldKey,
  86. body: new SingleChildScrollView(
  87. child: new Container(
  88. padding: new EdgeInsets.all(16.0),
  89. decoration: new BoxDecoration(image: backgroundImage),
  90. child: new Column(
  91. mainAxisAlignment: MainAxisAlignment.end,
  92. crossAxisAlignment: CrossAxisAlignment.center,
  93. children: <Widget>[
  94. new SizedBox(
  95. height: screenSize.height / 2 + 20,
  96. child: new Column(
  97. mainAxisAlignment: MainAxisAlignment.center,
  98. children: <Widget>[
  99. new Text(
  100. "CREATE ACCOUNT",
  101. textAlign: TextAlign.center,
  102. style: headingStyle,
  103. )
  104. ],
  105. )),
  106. new Column(
  107. children: <Widget>[
  108. new Form(
  109. key: _formKey,
  110. autovalidate: _autovalidate,
  111. //onWillPop: _warnUserAboutInvalidData,
  112. child: new Column(
  113. children: <Widget>[
  114. new FutureBuilder<File>(
  115. future: _imageFile,
  116. builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
  117. if (snapshot.connectionState == ConnectionState.done &&
  118. snapshot.data != null) {
  119. return new Image.file(snapshot.data);
  120. } else if (snapshot.error != null) {
  121. return const Text('error picking image.');
  122. } else {
  123. return const Text('You have not yet picked an image.');
  124.  
  125. }
  126. },
  127. ),
  128. new RaisedButton.icon(onPressed: _showaddphoto, icon: new Icon(Icons.add_a_photo), label: new Text('Add Photo')),
  129.  
  130. new InputField(
  131. hintText: "product title",
  132. obscureText: false,
  133. textInputType: TextInputType.text,
  134. textStyle: textStyle,
  135. textFieldColor: textFieldColor,
  136. icon: Icons.person_outline,
  137. iconColor: Colors.white,
  138. bottomMargin: 20.0,
  139. validateFunction: (value)=> value.isEmpty ? 'UserName can\'t be empty' : null,
  140. onSaved: (value)=> _productTitle = value,
  141. ),
  142.  
  143. new InputField(
  144. hintText: "Category",
  145. obscureText: false,
  146. textInputType: TextInputType.emailAddress,
  147. textStyle: textStyle,
  148. textFieldColor: textFieldColor,
  149. icon: Icons.mail_outline,
  150. iconColor: Colors.white,
  151. bottomMargin: 20.0,
  152. validateFunction: (value)=> value.isEmpty ? 'Email can\'t be empty' : null,
  153. onSaved: (value)=> _category = value,
  154. ),
  155. new InputField(
  156. hintText: "Contact Number",
  157. obscureText: true,
  158. textInputType: TextInputType.text,
  159. textStyle: textStyle,
  160. textFieldColor: textFieldColor,
  161. icon: Icons.lock_open,
  162. iconColor: Colors.white,
  163. bottomMargin: 40.0,
  164. validateFunction: (value)=> value.isEmpty ? 'Contact number can\'t be empty' : null,
  165. onSaved: (value)=> _contactNumber = value,
  166. ),
  167. new RoundedButton(
  168. buttonName: "Continue",
  169. onTap: validateAndSubmit,
  170. width: screenSize.width,
  171. height: 50.0,
  172. bottomMargin: 10.0,
  173. borderWidth: 1.0)
  174. ],
  175. )),
  176. new TextButton(
  177. buttonName: "Terms & Condition", onPressed: _onPressed,buttonTextStyle: buttonTextStyle,)
  178. ],
  179. )
  180. ],
  181. ),
  182. ),
  183. ));
  184. }
  185. }
Add Comment
Please, Sign In to add comment