Skip to content

Instantly share code, notes, and snippets.

@kwmt
Created December 14, 2018 01:57
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 kwmt/ba4701b2b80b3675e7c58ea9b841f45f to your computer and use it in GitHub Desktop.
Save kwmt/ba4701b2b80b3675e7c58ea9b841f45f to your computer and use it in GitHub Desktop.
Scalable and page selectable
class ScalableImageScreen extends StatelessWidget {
final List<String> imageUrls;
final int position;
ScalableImageScreen({Key key, this.imageUrls, this.position})
: super(key: key);
@override
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: position,
length: imageUrls.length,
child: _PageSelector(imageUrls: imageUrls, position: position),
);
}
}
class _PageSelector extends StatelessWidget {
const _PageSelector({this.imageUrls, this.position});
final List<String> imageUrls;
final int position;
@override
Widget build(BuildContext context) {
Widget previewWidget = Scaffold(
appBar: AppBar(
title: Text("preview"),
backgroundColor: Colors.black,
),
backgroundColor: Colors.black,
body: Column(
children: <Widget>[
Expanded(
child: TabBarView(
children: imageUrls.map((String imageUrl) {
return Container(
child: Center(
child: PhotoView(
imageProvider: NetworkImage(imageUrl),
minScale: PhotoViewComputedScale.contained * 1.0,
maxScale: 2.0,
),
),
);
}).toList()),
),
],
),
);
UniqueKey key = UniqueKey();
return Dismissible(
key: key,
direction: DismissDirection.vertical,
onDismissed: (direction) {
Navigator.pop(context);
},
child: previewWidget,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment