Skip to content

Instantly share code, notes, and snippets.

@dariadobsai
Created November 6, 2020 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariadobsai/07a2994baa867a1b0c123903776f3599 to your computer and use it in GitHub Desktop.
Save dariadobsai/07a2994baa867a1b0c123903776f3599 to your computer and use it in GitHub Desktop.
Using Bloc to pass data backward
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