build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  return CustomScaffold(
      appBar: AppBar(
          backgroundColor: CustomStylesConfig.primaryColor,
          leading: CloseButton(
            onPressed: () {
              CustomNavigation.pop(context);
            },
          ),
          actions: [
            isDownloadIcon
                ? IconButton(
                onPressed: () async {
                  isDownload.value = true;
                  // await DownloadServices.saveNetworkImage(
                  //     url: image.first,
                  //     name: '${DateTime.now().millisecondsSinceEpoch}',
                  //     ext: 'png');
                  var snackBar = SnackBar(
                      content: CustomText.headingSmall(
                        'Download not complete!, it is commented',
                        color: MyColors.whiteColor,
                        fontWeight: FontWeight.w400,
                        fontSize: 16,
                      ),
                      duration: Duration(seconds: 2));
                  isDownload.value = false;
                  // ignore: use_build_context_synchronously
                  ScaffoldMessenger.of(context).showSnackBar(snackBar);
                },
                icon: const Icon(
                  Icons.download_rounded,
                  size: 30,
                  color: MyColors.whiteColor,
                ))
                : Container(),
            isShareIcon
                ? IconButton(
              onPressed: () async {
                isDownload.value = true;
                // await DownloadServices.saveNetworkImage(
                //     url: image.first,
                //     name: '${DateTime.now().millisecondsSinceEpoch}',
                //     ext: 'png');
                var snackBar = SnackBar(
                    content: CustomText.headingSmall(
                      'Download not complete!, it is commented 2',
                      color: MyColors.whiteColor,
                      fontWeight: FontWeight.w400,
                      fontSize: 16,
                    ),
                    duration: Duration(seconds: 2));
                isDownload.value = false;
                // ignore: use_build_context_synchronously
                ScaffoldMessenger.of(context).showSnackBar(snackBar);
                // isDownload.value = true;
                // String? path = await DownloadServices.getFilePath(
                //     url: image.first,
                //     name: '${DateTime.now().millisecondsSinceEpoch}',
                //     ext: 'png');
                // isDownload.value = false;
                ///Todo commented
                // if (path != null) {
                //   final file = XFile(path);
                //   await FileServices.shareFiles(files: [file.path]);
                // }
              },
              padding: const EdgeInsets.only(
                right: 7,
              ),
              icon:const Icon(
                Icons.share,
                size: 26,
                color: MyColors.whiteColor,
              )/*Image.asset(
                    MyImagesUrl.userWalkReportShare,
                    color: MyColors.whiteColor,
                    scale: 7.5,
                  )*/,
            )
                : Container()
          ]),
      backgroundColor: MyColors.blackColor,
      body: ValueListenableBuilder(
          valueListenable: isDownload,
          builder: (context, downloadValue, child) {
            return Stack(
              children: [
                GestureDetector(
                    onTap: onTap,
                    behavior: HitTestBehavior.translucent,
                    child: Container(
                      width: double.infinity,
                      height: double.infinity,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        boxShadow: [
                          if (isBoxShadow)
                            BoxShadow(
                                color: Colors.black.withOpacity(0.2),
                                blurRadius: 0.0,
                                spreadRadius: 0.0,
                                offset: const Offset(0, 0))
                        ],
                        borderRadius: BorderRadius.circular(borderRadius),
                        color: color,
                      ),
                      child: PinchZoom(
                        // clipBehavior: true,
                        // height: double.infinity,
                        // width: double.infinity,
                        child: CustomImage(
                          height: double.infinity,
                          width: double.infinity,
                          isBackgroundImage: false,
                          fit: BoxFit.contain,
                          borderRadius: 0,
                          imageUrl: image[0],
                          /*  loadingBuilder: (context, child, loadingProgress) {
                          print("loadingProgress:::::::::::${loadingProgress}");
                          if (loadingProgress == null) {
                            // If there's no loading progress, return the child (the image)
                            return child;
                          } else {
                            return const Center(
                                child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                ParagraphText("Picture is Loading",
                                    color: MyColors.whiteColor),
                                vSizedBox,
                                CustomLoader(color: Colors.white),
                              ],
                            ));
                          }
                        },*/
                        ),
                      ), /*PhotoViewGallery.builder(
                        scrollPhysics: const BouncingScrollPhysics(),
                        scaleStateChangedCallback: (scaleState) {
                          // Logic to restrict zoom out beyond the original size

                          print("adtadtadtdatdatdatdt:::::::::::${scaleState}");
                          if (scaleState == PhotoViewScaleState.zoomedOut) {
                            scaleState = PhotoViewScaleState.initial;
                          }
                        },
                        builder: (BuildContext context, int index) {
                          switch (fileType) {
                            case CustomFileType.network:
                              {
                                return PhotoViewGalleryPageOptions(
                                    imageProvider:
                                        // fileType==CustomFileType.network?
                                        NetworkImage(image[index]),

                                    // :
                                    // AssetImage(image[index]),
                                    initialScale:
                                        PhotoViewComputedScale.contained * 1,
                                    scaleStateCycle: (scaleState) {
                                      print("datdatdatdtadtadatta::::::");
                                      var state = scaleState;
                                      if (state == PhotoViewScaleState.zoomedOut) {
                                        state = PhotoViewScaleState.initial;
                                      }

                                      return state;
                                    },
                                    minScale: PhotoViewComputedScale.contained * 1);
                              }
                            default:
                              return PhotoViewGalleryPageOptions(
                                  imageProvider:
                                      // fileType==CustomFileType.network?
                                      AssetImage(image[index]),
                                  // :
                                  // AssetImage(image[index]),
                                  initialScale: PhotoViewComputedScale.contained * 1,
                                  minScale: 0.2);
                          }
                        },
                        itemCount: image.length,
                        // loadingBuilder: (context, event) => Center(
                        //   child: Container(
                        //     width: 20.0,
                        //     height: 20.0,
                        //     child: CircularProgressIndicator(
                        //       value: event == null
                        //           ? 0
                        //           : event.cumulativeBytesLoaded
                        //     ),
                        //   ),
                        // ),
                        // backgroundDecoration: widget.backgroundDecoration,
                        // pageController: widget.pageController,
                        // onPageChanged: onPageChanged,
                      )*/
                    )),
                if (downloadValue)
                  Container(
                    color: Colors.black.withOpacity(0.8),
                    child: const Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        CustomLoader(color: MyColors.whiteColor),
                      ],
                    ),
                  )
              ],
            );
          }));

  // PageView(
  //   children:  image.map((i) {
  //     return Builder(
  //       builder: (BuildContext context) {
  //         return Image.asset(image[i],width: width,fit: BoxFit.fitWidth,);
  //       },
  //     );
  //   }).toList(),
  //       // ),
  //     ),
  //   ),
  // );
}