Skip to content

Instantly share code, notes, and snippets.

@GursheeshSingh
Last active July 10, 2020 18:49
Show Gist options
  • Save GursheeshSingh/5a30fae055d7b27617eb0760904f0da9 to your computer and use it in GitHub Desktop.
Save GursheeshSingh/5a30fae055d7b27617eb0760904f0da9 to your computer and use it in GitHub Desktop.
enum PhotoSource { ASSET, NETWORK }
enum PhotoStatus { LOADING, ERROR, LOADED }
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
PhotoSource photoSource;
PhotoStatus photoStatus;
String source;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 200,
child: Stack(
children: [
Positioned.fill(
child: Container(
color: Colors.grey.shade200,
child: photoSource == PhotoSource.NETWORK
? Image.network(source, height: 200)
: photoSource == PhotoSource.ASSET
? Image.asset(source, height: 200)
: Container(
color: Colors.grey.shade200, height: 200),
),
),
Center(
child: photoStatus == PhotoStatus.LOADING
? CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.red))
: photoStatus == PhotoStatus.ERROR
? Icon(MaterialIcons.error,
color: Colors.red, size: 40)
: Container(),
)
],
),
),
SizedBox(height: 16),
RaisedButton(
onPressed: () async {
},
child: Text('Select image'),
)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment