import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flyinsono/architecture/router/index.dart';

class MeasureImage extends FStatefulWidget implements FPage {
  @override
  final String pageName;
  late final String imageToken;

  MeasureImage(
    String token, {
    this.pageName = 'MeasureImage',
  }) {
    this.imageToken = token;
  }

  @override
  FState<FStatefulWidget> createState() {
    return MeasureImageState();
  }
}

class MeasureImageState extends FState<MeasureImage> {
  @override
  void initState() {
    // 强制横屏
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
    super.initState();
  }

  @override
  FWidget build(BuildContext context) {
    return FStack(
      children: [
        FContainer(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          color: Colors.white,
          child: FImage.network(widget.imageToken),
        ),
        FPositioned(
          top: 15,
          right: 10,
          child: FIconButton(
            businessParent: this.widget,
            name: "close",
            icon: FIcon(
              Icons.close,
              size: 25,
              color: Color.fromARGB(255, 212, 74, 64),
            ),
            onPressed: () {
              router.back();
            },
          ),
        )
      ],
    );
  }

  @override
  void dispose() {
    // 强制竖屏
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    super.dispose();
  }
}
