-
Modifying the Flutter package-applied as an internal projectFlutter/mobile 2020. 5. 12. 15:40
The original article for this is at the link below.
https://blog.naver.com/chandong83/221876364791
Flutter(플러터) 패키지(Package) 수정하기 - with GitHub
지난번 "QR 코드 스캔" 패키지를 이용해 아주 간단하게 "QR 코드 스캔" 예제를 제...
blog.naver.com
https://blog.naver.com/chandong83/221872148573
Flutter(플러터) QR 코드 스캔(QR Code Scan) 초간단 예제(Simple example)
위 Flutter(Dart) 패키지 사이트에 접속해 qrcode를 검색하면 많은 패키지들이 보일 것이다.위 리스트 중...
blog.naver.com
In the above article, I showed you how to make a QR code scan project very easy using an external package.
Modifying the Flutter package-with GitHub
https://blog.naver.com/chandong83/221872148573 Flutter(플러터) QR 코드 스캔(QR Code Scan) 초간단 예제(Simple example) 위 Flutter(Dart) 패키지 사이트에 접속해 qrcode를 검색하면 많은 패키지들이 보일..
genis.tistory.com
However, there was a situation in which the used package had to be modified because it was not necessary.
In the previous article (link above), I covered how to modify the Flutter package using Github.
There are two main ways to modify external packages.
-
How to fork the package source code to your own github (or a separate git server, etc.).
(Just covered in the previous article)
-
How to download and modify the package source code and apply it to the project.
The second method is how to download the package and apply it to the project.
Some of the parts that are going on from now on are explained in the last article, so there are some simplified parts, so please read the previous article first for better understanding.
[sticker]
Now then shall we start !?
1. Get source code
First, let's get the package source code.
https://pub.dev/packages/qrscan
qrscan | Flutter Package
A Plug-in for dart, which help you scanning barcode and qrcode with android device.
pub.dev
Access the link above.
When you access the link, you will see a link to the source code repository at the top right.
Click this to go to the source code location.
When accessing the source code repository (github), select "Clone or download"> "Download ZIP" to download the source code and extract it.
Create a folder called "packages" in the same location as the project to which the extracted source code folder will be applied and move it there.
The key here is that the package folder is not contained within the project, but should be outside the project.
If you add it into the project, you will have unexpectedly huge errors and lightning gatherings.
Wow ... by the way, do you still use the word "lightning" ???
Suddenly, I want to eat latte ...
2. Modify pubspec.yaml
Now open pubspec.yaml in the project folder and specify the location of the package as shown below.
qrscan: path: ../packages/qrcode_scanner-master/
In the "package" folder directly above the current project, the "qrcode_scanner-master" folder is designated as the "qrscan" package.
For reference, path can be an absolute path or a relative path.
When distributing source code, relative paths may be easier to manage than absolute paths.
3. Apply package
Now that the package has been replaced with an internal path, let's apply it for use in the project.
The method of applying the package will use one of the following two.
Please refer to the previous article for details on this.
If the package was imported locally while using the same package ...
flutter pub upgrade
If this is the first time you've met the package...
flutter pub get
4. Package Modifications
As in the previous article, let's delete the flash button.
Let's open the source code of the following path in the qrcode package.
qrcode_scanner-master \ android \ src \ main \ java \ com \ shinow \ qrscan \ SecondActivity.java
Path of package source code
Now the code at the end of the onCreate function in this ScondActivity.java
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); sensorEventListener = new LightSensorEventListener(lightLayout);
Modify as follows.
// sensorManager = (SensorManager) getSystemService (Context.SENSOR_SERVICE); // lightSensor = sensorManager.getDefaultSensor (Sensor.TYPE_LIGHT); // sensorEventListener = new LightSensorEventListener (lightLayout); lightLayout.setVisibility (View.INVISIBLE);
If you have modified the qrcode package, go back to the current project and run it immediately.
For reference, if you download and use the package, you can see that it is applied immediately without re-running flutter pub get or flutter pub every time you modify the package.
5. Execution result
Left: Before change, Right: After change Personally ... I fork it on github, download it, debug and modify it, and when it is done, I commit to github again and use it to think that it would be correct.
'Flutter > mobile' 카테고리의 다른 글
Flutter Singleton class (0) 2020.05.13 Flutter Back Button (0) 2020.05.13 Modifying the Flutter package-with GitHub (0) 2020.05.12 Flutter QR Code Scan Simple example (0) 2020.05.12 Flutter Applying a simple splash screen (app logo screen)-Android edition (0) 2020.05.12 -