Skip to content

Commit

Permalink
proper loading of images + add rotation button
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed May 11, 2021
1 parent 9ac9b67 commit 6742706
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 41 deletions.
2 changes: 1 addition & 1 deletion flutter_server/lib/com/hydrologis/gss/libs/formutils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ServerFormHelper implements AFormhelper {
padding: SmashUI.defaultPadding(),
child: GestureDetector(
onDoubleTap: () {
openImageDialog(context, "", id);
openImageDialog(context, "", id, hideRotate: true);
},
child: img,
),
Expand Down
37 changes: 11 additions & 26 deletions flutter_server/lib/com/hydrologis/gss/libs/maputils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Marker buildImage(MapstateModel mapState, double screenHeight, var x, var y,
// model.selectedNoteId = dataId;
// model.refresh();
// } else {
openImageDialog(mapState.currentMapContext, name, dataId);
openImageDialog(mapState.currentMapContext, name, dataId,
hideRotate: false);
// }
},
child: imageWidget,
Expand Down Expand Up @@ -292,33 +293,16 @@ openLogDialog(BuildContext context, String logInfo) async {
context: context, builder: (BuildContext context) => openLogDialog);
}

openImageDialog(BuildContext context, String name, int imageId) {
openImageDialog(BuildContext context, String name, int imageId,
{hideRotate = true}) {
var h = MediaQuery.of(context).size.height;
var size = 700.0;
Dialog mapSelectionDialog = Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
child: Container(
height: size,
width: size,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
name.isNotEmpty
? Padding(
padding: const EdgeInsets.all(8.0),
child: SmashUI.titleText(
name,
textAlign: TextAlign.center,
),
)
: Container(),
NetworkImageWidget("$WEBAPP_URL/imagedata/$imageId", h * 0.8),
// TODO change once the NetworkImageWidget has auth
// NetworkImageWidget("$API_IMAGEDATA/$imageId", h * 0.6),
],
),
),
child: NetworkImageWidget(
"$WEBAPP_URL/imagedata/$imageId",
name,
h * 0.7,
hideRotate: hideRotate,
),
);
showDialog(
Expand Down Expand Up @@ -963,7 +947,8 @@ class _AttributesTableWidgetState extends State<AttributesTableWidget> {
tooltip: "View note.",
onPressed: () {
if (attr.marker is Image) {
openImageDialog(context, attr.text, attr.id);
openImageDialog(context, attr.text, attr.id,
hideRotate: false);
} else {
openNoteDialog(context, attr.id);
}
Expand Down
86 changes: 72 additions & 14 deletions flutter_server/lib/com/hydrologis/gss/libs/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import 'package:smashlibs/smashlibs.dart';
class NetworkImageWidget extends StatefulWidget {
final double _height;
final String _imageUrl;
NetworkImageWidget(this._imageUrl, this._height, {Key key}) : super(key: key);
final String _title;
final bool hideRotate;
NetworkImageWidget(this._imageUrl, this._title, this._height,
{this.hideRotate = true, Key key})
: super(key: key);

@override
_NetworkImageWidgetState createState() =>
Expand All @@ -30,6 +34,7 @@ class _NetworkImageWidgetState extends State<NetworkImageWidget> {
bool _imageReady = false;
List<int> _bytes;
String error;
int quarterTurns = 0;

_NetworkImageWidgetState(this._imageUrl, this._height);

Expand Down Expand Up @@ -76,27 +81,80 @@ class _NetworkImageWidgetState extends State<NetworkImageWidget> {
child: Center(child: SmashCircularProgress()),
);
} else {
// IMG.Image img = ImageUtilities.imageFromBytes(_bytes);
// print(img.width);
// print(img.height);
Image image = Image.memory(
_bytes,
fit: BoxFit.none,
// width: 400,
// height: 600,
// width: 4608,
// height: 2184,
);

return Container(
child: Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: image,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
if (widget._title != null && widget._title.length > 0)
Padding(
padding: const EdgeInsets.all(8.0),
child: SmashUI.titleText(widget._title),
),
Padding(
padding: const EdgeInsets.all(18.0),
child: RotatedBox(
quarterTurns: quarterTurns,
child: image,
),
),
if (!widget.hideRotate)
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: FloatingActionButton(
mini: true,
backgroundColor: SmashColors.mainDecorations,
child: Icon(MdiIcons.rotateRight),
onPressed: () {
setState(() {
quarterTurns++;
if (quarterTurns > 3) {
quarterTurns = 0;
}
});
},
),
)
],
),
);

// return Stack(
// children: [
// Container(
// child: Expanded(
// flex: 1,
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: RotatedBox(
// quarterTurns: 0,
// child: image,
// ),
// ),
// ),
// ),
// Align(
// alignment: Alignment.bottomRight,
// child: FloatingActionButton(
// child: Icon(MdiIcons.rotateRight),
// onPressed: () {
// setState(() {
// quarterTurns++;
// if (quarterTurns > 3) {
// quarterTurns = 0;
// }
// });
// },
// ),
// )
// ],
// );
}
}
}
Expand Down

0 comments on commit 6742706

Please sign in to comment.