import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:sapaly_shop/themes/app_theme.dart';

class PhotoScreen extends StatefulWidget {
  final String image;
  const PhotoScreen(this.image);

  @override
  _PhotoScreenState createState() => _PhotoScreenState();
}

class _PhotoScreenState extends State<PhotoScreen> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final double paddingTop = MediaQueryData.fromWindow(window).padding.top;
    return Container(
      color: Colors.black,
      child: Stack(
        children: <Widget>[
          PhotoView(
              loadingBuilder: (_, chunk) => const Center(
                  child: CircularProgressIndicator(
                      color: AppTheme.lightPrimaryColor)),
              imageProvider: CachedNetworkImageProvider(widget.image)),
          OrientationBuilder(
            builder: (cntxt, orientation) {
              double height = (orientation == Orientation.portrait
                      ? MediaQuery.of(context).size.height
                      : MediaQuery.of(context).size.width) *
                  0.049;
              return Container(
                height: height,
                alignment: Alignment.centerRight,
                width: MediaQuery.of(context).size.width * 0.98,
                margin: EdgeInsets.only(top: paddingTop),
                child: FittedBox(
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      onTap: () => Navigator.of(cntxt).pop(),
                      child: Icon(
                        Icons.close,
                        color: Colors.white,
                        size: height * 0.8,
                      ),
                    ),
                  ),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
