-1

I'm developing a Flutter app.

I have used a function written by me to calculate the sizes of every stuff. This was called scaleAdapter and its signature was this one:

scaleAdapter(aNumber)

This is used everywhere in the project.
I recently however discovered that this approach is not useful in many cases and I want to migrate to the flutter_screenutil package which is very good. The fact is that now in every file I should substitute

scaleAdapter(aNumber) with aNumber.aUnit
where aUnit is:

  • w for horizontal
  • h for vertical values
  • sp for size values
  • r for round values (such as border-radius)

in a concrete example

SizedBox(
  width: scaleAdapter(22),
  height: scaleAdapter(22),
  child: SvgPicture.asset(
    'assets/images/svg/yellow/prezzo.svg',
  ),
),

Now it must become:

SizedBox(
  width: 22.w,
  height: 22.h,
  child: SvgPicture.asset(
    'assets/images/svg/yellow/prezzo.svg',
  ),
),

Since it is insane to think about manually substituting everything I was wondering if there is some function in IntelliJ or also VSCode that can do the work for me.

I am able with IntelliJ to search for a specific pattern using a RegEx, (for example by searching width: scaleAdapter\(.\) I find all the width values with the old function) but I don't know how to keep the original value when substituting.

Any help please?

MendelG
  • 14,885
  • 4
  • 25
  • 52
Ale TheFe
  • 1,540
  • 15
  • 43
  • You can easily combine this into one find/replace , see https://regex101.com/r/pOb1J5/1. Works in one file or across multiple files. – Mark Aug 10 '23 at 20:46

1 Answers1

0

In VSC

regex search for: width: scaleAdapter\(([^)]+)\)

replace with: width: $1.w

similar for the other cases of h, sp and r

rioV8
  • 24,506
  • 3
  • 32
  • 49