Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extracting widget doesn't create members #59819

Open
stephane-archer opened this issue Dec 30, 2024 · 0 comments
Open

extracting widget doesn't create members #59819

stephane-archer opened this issue Dec 30, 2024 · 0 comments
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stephane-archer
Copy link

stephane-archer commented Dec 30, 2024

Input:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lutme/adaptive_image.dart';
import 'package:lutme/exposure_analysis_tool_change_notifier.dart';
import 'package:lutme/exposure_analysis_widget.dart';
import 'package:lutme/img_with_before_and_after_click.dart';
import 'package:lutme/lut_intensity_selector.dart';
import 'package:lutme/preview_generator_change_notifier.dart';
import 'package:lutme/ref_image_transform_provider.dart';
import 'package:lutme/selected_lut_change_notifier.dart';

class MainPreview extends ConsumerWidget {
  const MainPreview({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    AsyncValue<String?> imagePathAsyncValue = ref.watch(refImageTransformProvider);
   return imagePathAsyncValue.when<Widget>(data: (imagePath) {
// START EXTRACTING WIDGET
      SelectedLutChangeNotifier selectedLutChangeNotifier =
          ref.watch(selectedLutProvider);
      ExposureAnalysisToolChangeNotifier exposureAnalysisToolChangeNotifier =
          ref.watch(exposureAnalysisToolProvider);
      PreviewGeneratorChangeNotifier previewGeneratorChangeNotifier =
          ref.watch(previewGeneratorProvider);
      if (imagePath == null) {
        return const SizedBox.shrink();
      }
      String? pathImgSelectedLut = selectedLutChangeNotifier.pathImgSelectedLut;
      if (pathImgSelectedLut == null) {
        if (exposureAnalysisToolChangeNotifier.isActivated) {
          return ExposureAnalysisWidget(
              imagePath, previewGeneratorChangeNotifier);
        }
        return AdaptiveImage(FileImage(File(imagePath)), false);
      }
      if (exposureAnalysisToolChangeNotifier.isActivated) {
        return ExposureAnalysisWidget(
            pathImgSelectedLut, previewGeneratorChangeNotifier);
      }
      return Column(
        children: [
          Expanded(
            flex: 8,
            child: ImgWithBeforeAndAfterClick(
                before: AdaptiveImage(FileImage(File(imagePath)), false),
                after: OpacityStack(
                  before: AdaptiveImage(FileImage(File(imagePath)), false),
                  after:
                      AdaptiveImage(FileImage(File(pathImgSelectedLut)), false),
                )),
          ),
          const SizedBox(height: 10.0),
          const LutIntensitySelector(),
        ],
      );
// END EXTRACTING WIDGET
    }, error: (e, s) {
      return Text("Error: $e");
    }, loading: () {
      return const CircularProgressIndicator();
    });
  }
}

output:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lutme/adaptive_image.dart';
import 'package:lutme/exposure_analysis_tool_change_notifier.dart';
import 'package:lutme/exposure_analysis_widget.dart';
import 'package:lutme/img_with_before_and_after_click.dart';
import 'package:lutme/lut_intensity_selector.dart';
import 'package:lutme/preview_generator_change_notifier.dart';
import 'package:lutme/ref_image_transform_provider.dart';
import 'package:lutme/selected_lut_change_notifier.dart';

class MainPreview extends ConsumerWidget {
  const MainPreview({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    AsyncValue<String?> imagePathAsyncValue = ref.watch(refImageTransformProvider);
   return imagePathAsyncValue.when<Widget>(data: (imagePath) {
      return _MainPreviewOnData();
    }, error: (e, s) {
      return Text("Error: $e");
    }, loading: () {
      return const CircularProgressIndicator();
    });
  }
}

class _MainPreviewOnData extends StatelessWidget {
  const _MainPreviewOnData({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    SelectedLutChangeNotifier selectedLutChangeNotifier =
        ref.watch(selectedLutProvider);
    ExposureAnalysisToolChangeNotifier exposureAnalysisToolChangeNotifier =
        ref.watch(exposureAnalysisToolProvider);
    PreviewGeneratorChangeNotifier previewGeneratorChangeNotifier =
        ref.watch(previewGeneratorProvider);
    if (imagePath == null) {
      return const SizedBox.shrink();
    }
    String? pathImgSelectedLut = selectedLutChangeNotifier.pathImgSelectedLut;
    if (pathImgSelectedLut == null) {
      if (exposureAnalysisToolChangeNotifier.isActivated) {
        return ExposureAnalysisWidget(
            imagePath, previewGeneratorChangeNotifier);
      }
      return AdaptiveImage(FileImage(File(imagePath)), false);
    }
    if (exposureAnalysisToolChangeNotifier.isActivated) {
      return ExposureAnalysisWidget(
          pathImgSelectedLut, previewGeneratorChangeNotifier);
    }
    return Column(
      children: [
        Expanded(
          flex: 8,
          child: ImgWithBeforeAndAfterClick(
              before: AdaptiveImage(FileImage(File(imagePath)), false),
              after: OpacityStack(
                before: AdaptiveImage(FileImage(File(imagePath)), false),
                after:
                    AdaptiveImage(FileImage(File(pathImgSelectedLut)), false),
              )),
        ),
        const SizedBox(height: 10.0),
        const LutIntensitySelector(),
      ],
    );
  }
}

ref and imagePath doesn't exist in the newly extracted widget _MainPreviewOnData

expected code:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lutme/adaptive_image.dart';
import 'package:lutme/exposure_analysis_tool_change_notifier.dart';
import 'package:lutme/exposure_analysis_widget.dart';
import 'package:lutme/img_with_before_and_after_click.dart';
import 'package:lutme/lut_intensity_selector.dart';
import 'package:lutme/preview_generator_change_notifier.dart';
import 'package:lutme/ref_image_transform_provider.dart';
import 'package:lutme/selected_lut_change_notifier.dart';

class MainPreview extends ConsumerWidget {
  const MainPreview({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    AsyncValue<String?> imagePathAsyncValue =
        ref.watch(refImageTransformProvider);
    return imagePathAsyncValue.when<Widget>(data: (imagePath) {
      return _MainPreviewOnData(imagePath);
    }, error: (e, s) {
      return Text("Error: $e");
    }, loading: () {
      return const CircularProgressIndicator();
    });
  }
}

class _MainPreviewOnData extends ConsumerWidget {
  final String? _imagePath;
  const _MainPreviewOnData(
    this._imagePath,
  );

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    SelectedLutChangeNotifier selectedLutChangeNotifier =
        ref.watch(selectedLutProvider);
    ExposureAnalysisToolChangeNotifier exposureAnalysisToolChangeNotifier =
        ref.watch(exposureAnalysisToolProvider);
    PreviewGeneratorChangeNotifier previewGeneratorChangeNotifier =
        ref.watch(previewGeneratorProvider);
    String? imagePath = _imagePath;
    if (imagePath == null) {
      return const SizedBox.shrink();
    }
    String? pathImgSelectedLut = selectedLutChangeNotifier.pathImgSelectedLut;
    if (pathImgSelectedLut == null) {
      if (exposureAnalysisToolChangeNotifier.isActivated) {
        return ExposureAnalysisWidget(
            imagePath, previewGeneratorChangeNotifier);
      }
      return AdaptiveImage(FileImage(File(imagePath)), false);
    }
    if (exposureAnalysisToolChangeNotifier.isActivated) {
      return ExposureAnalysisWidget(
          pathImgSelectedLut, previewGeneratorChangeNotifier);
    }
    return Column(
      children: [
        Expanded(
          flex: 8,
          child: ImgWithBeforeAndAfterClick(
              before: AdaptiveImage(FileImage(File(imagePath)), false),
              after: OpacityStack(
                before: AdaptiveImage(FileImage(File(imagePath)), false),
                after:
                    AdaptiveImage(FileImage(File(pathImgSelectedLut)), false),
              )),
        ),
        const SizedBox(height: 10.0),
        const LutIntensitySelector(),
      ],
    );
  }
}
@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Dec 30, 2024
@keertip keertip added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) analyzer-assist Issues with analysis server assists P3 A lower priority bug or feature request labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants