Skip to content

Commit

Permalink
Added image picker
Browse files Browse the repository at this point in the history
  • Loading branch information
kdebiec committed Aug 25, 2019
1 parent f130b88 commit 2f44975
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/ui/change_identity_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class _ChangeIdentityScreenState extends State<ChangeIdentityScreen> {
data: PersonDelegateData(
name: idsTuple.item1[index].name,
mId: idsTuple.item1[index].mId,
profileImage: idsTuple.item1[index].avatar,
),
isSelectable: true,
onPressed: () {
Expand Down
35 changes: 25 additions & 10 deletions lib/ui/create_identity_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:image_picker/image_picker.dart';

import 'dart:io';
import 'dart:convert';

import 'package:retroshare/common/styles.dart';
import 'package:retroshare/common/bottom_bar.dart';
Expand All @@ -22,6 +23,8 @@ class CreateIdentityScreen extends StatefulWidget {
class _CreateIdentityScreenState extends State<CreateIdentityScreen> {
TextEditingController nameController = TextEditingController();
File _image;
String _imageBase64 = '';
int _imageSize;

@override
void dispose() {
Expand All @@ -34,6 +37,8 @@ class _CreateIdentityScreenState extends State<CreateIdentityScreen> {

setState(() {
_image = image;
_imageSize = image.readAsBytesSync().length;
_imageBase64 = base64.encode(image.readAsBytesSync());
});
}

Expand Down Expand Up @@ -110,14 +115,24 @@ class _CreateIdentityScreenState extends State<CreateIdentityScreen> {
child: Container(
height: 300 * 0.7,
width: 300 * 0.7,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
300 * 0.7 * 0.33),
image: DecorationImage(
fit: BoxFit.fitWidth,
image: _image == null
? AssetImage('assets/profile.jpg')
: FileImage(_image),
decoration: _image == null
? null
: BoxDecoration(
borderRadius:
BorderRadius.circular(
300 * 0.7 * 0.33),
image: DecorationImage(
fit: BoxFit.fitWidth,
image: FileImage(_image),
),
),
child: Visibility(
visible: _imageBase64.isEmpty,
child: Center(
child: Icon(
Icons.person,
size: 300 * 0.7,
),
),
),
),
Expand Down Expand Up @@ -169,8 +184,8 @@ class _CreateIdentityScreenState extends State<CreateIdentityScreen> {
height: 2 * appBarHeight / 3,
child: FlatButton(
onPressed: () async {
Identity id = await createIdentity(
Identity('', false, nameController.text));
Identity id = await createIdentity(Identity(
'', false, nameController.text, _imageBase64), _imageSize);
final store = StoreProvider.of<AppState>(context);
store.dispatch(ChangeCurrentIdentityAction(id));

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:

tuple: ^1.0.2
flutter_redux: ^0.5.3
image_picker: ^0.6.0+20
sliding_up_panel: ^0.3.4

# Toast
Expand Down

0 comments on commit 2f44975

Please sign in to comment.