|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:image_picker/image_picker.dart'; |
| 3 | + |
| 4 | +class AddBlog extends StatefulWidget { |
| 5 | + AddBlog({Key key}) : super(key: key); |
| 6 | + |
| 7 | + @override |
| 8 | + _AddBlogState createState() => _AddBlogState(); |
| 9 | +} |
| 10 | + |
| 11 | +class _AddBlogState extends State<AddBlog> { |
| 12 | + PickedFile _imageFile; |
| 13 | + final ImagePicker _picker = ImagePicker(); |
| 14 | + IconData icon = Icons.image; |
| 15 | + @override |
| 16 | + Widget build(BuildContext context) { |
| 17 | + return Scaffold( |
| 18 | + appBar: AppBar( |
| 19 | + elevation: 0, |
| 20 | + backgroundColor: Colors.white54, |
| 21 | + leading: IconButton(icon: Icon(Icons.clear), onPressed: null), |
| 22 | + actions: <Widget>[ |
| 23 | + Padding( |
| 24 | + padding: const EdgeInsets.all(8.0), |
| 25 | + child: FlatButton( |
| 26 | + onPressed: null, |
| 27 | + child: Text( |
| 28 | + "Submit", |
| 29 | + style: TextStyle(color: Colors.teal, fontSize: 20), |
| 30 | + )), |
| 31 | + ) |
| 32 | + ], |
| 33 | + ), |
| 34 | + body: SingleChildScrollView( |
| 35 | + child: Column( |
| 36 | + children: <Widget>[ |
| 37 | + textField(), |
| 38 | + textField2(), |
| 39 | + ], |
| 40 | + ), |
| 41 | + ), |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + Widget textField() { |
| 46 | + return Padding( |
| 47 | + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), |
| 48 | + child: TextFormField( |
| 49 | + // controller: _name, |
| 50 | + validator: (value) { |
| 51 | + if (value.isEmpty) return "Name can't be empty"; |
| 52 | + |
| 53 | + return null; |
| 54 | + }, |
| 55 | + maxLength: 100, |
| 56 | + maxLines: null, |
| 57 | + decoration: InputDecoration( |
| 58 | + prefixIcon: IconButton( |
| 59 | + icon: Icon( |
| 60 | + icon, |
| 61 | + color: Colors.green, |
| 62 | + ), |
| 63 | + onPressed: takePhoto), |
| 64 | + border: OutlineInputBorder( |
| 65 | + borderSide: BorderSide( |
| 66 | + color: Colors.teal, |
| 67 | + )), |
| 68 | + focusedBorder: OutlineInputBorder( |
| 69 | + borderSide: BorderSide( |
| 70 | + color: Colors.orange, |
| 71 | + width: 2, |
| 72 | + )), |
| 73 | + labelText: "Cover Image and Title", |
| 74 | + ), |
| 75 | + ), |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + Widget textField2() { |
| 80 | + return Padding( |
| 81 | + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), |
| 82 | + child: TextFormField( |
| 83 | + // controller: _name, |
| 84 | + validator: (value) { |
| 85 | + if (value.isEmpty) return "Name can't be empty"; |
| 86 | + |
| 87 | + return null; |
| 88 | + }, |
| 89 | + // maxLength: 100, |
| 90 | + maxLines: null, |
| 91 | + decoration: InputDecoration( |
| 92 | + border: OutlineInputBorder( |
| 93 | + borderSide: BorderSide( |
| 94 | + color: Colors.teal, |
| 95 | + )), |
| 96 | + focusedBorder: OutlineInputBorder( |
| 97 | + borderSide: BorderSide( |
| 98 | + color: Colors.orange, |
| 99 | + width: 2, |
| 100 | + )), |
| 101 | + labelText: "body", |
| 102 | + ), |
| 103 | + ), |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | + void takePhoto() async { |
| 108 | + final pickedFile = await _picker.getImage( |
| 109 | + source: ImageSource.gallery, |
| 110 | + ); |
| 111 | + setState(() { |
| 112 | + _imageFile = pickedFile; |
| 113 | + icon = Icons.check_box; |
| 114 | + }); |
| 115 | + } |
| 116 | +} |
0 commit comments