Created
November 6, 2020 10:49
-
-
Save dariadobsai/07a2994baa867a1b0c123903776f3599 to your computer and use it in GitHub Desktop.
Using Bloc to pass data backward
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _HomePageState extends State<HomePage> { | |
File _image; | |
final picker = ImagePicker(); | |
@override | |
Widget build(BuildContext context) { | |
return SafeArea( | |
child: Scaffold( | |
body: Center( | |
child: BlocBuilder<PhotoBloc, PhotoState>( | |
cubit: BlocProvider.of<PhotoBloc>( | |
context), // provide the local bloc instance | |
builder: (context, state) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
GestureDetector( | |
onTap: () { | |
_showSelectionDialog(); | |
}, | |
child: Container( | |
height: 150, | |
width: 150, | |
child: state is PhotoInitial | |
? Image.asset( | |
'assets/images/user.png') // set a placeholder image when no photo is set | |
: Image.file((state as PhotoSet).photo), | |
), | |
), | |
SizedBox(height: 50), | |
Text( | |
state is PhotoInitial | |
? 'Please select your profile photo' | |
: 'Nice photo:)', | |
style: TextStyle(fontSize: 22), | |
), | |
], | |
); | |
}, | |
), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment