-
Modifying the Flutter package-with GitHubFlutter/mobile 2020. 5. 12. 15:32
https://blog.naver.com/chandong83/221872148573
Flutter(플러터) QR 코드 스캔(QR Code Scan) 초간단 예제(Simple example)
위 Flutter(Dart) 패키지 사이트에 접속해 qrcode를 검색하면 많은 패키지들이 보일 것이다.위 리스트 중...
blog.naver.com
I made a very simple "QR code scan" example using the "QR code scan" package last time.
By the way ... I see an unnecessary (I use) flash button on the QR scan screen.
In this way, I am trying to find out about a situation in which the seasoning (?) Needs to be changed.
Now, let's see how to modify the package to suit your taste.
There are two main ways to modify a package.
First, how to fork the package source code to your own github (or a separate git server, etc.)
Second, it is a method of importing and modifying the package source code into the project.
In conclusion, you can import and modify the source code anywhere.
For reference, in node.js, the installed module (here package) could be modified and used by using the patch library, but the concept seems similar in some ways.
In this article, we will cover the first of the two methods above, how to import and use the source code to your github fork.
And from now on, it is assumed that the QR code scan project created last time is already explained, so if necessary, please read the article first.
1. Access the package source code. Fork it with your own GitHub.
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
If you access the link above and look to the right, you will see the source code repository.
Click this to go to the source code location.
If you have moved to the source code repository, click the "Fork" button at the top right to bring it to your repository.
At this time, of course, you must be logged in to github.
In this way, click "Clone or download" on the imported package to get the address.
https://github.com/chandong83/qrcode_scanner.git
chandong83/qrcode_scanner
🛠 Flutter QR code scanner plugin. Contribute to chandong83/qrcode_scanner development by creating an account on GitHub.
github.com
Now, add this address to the "pubspec.yaml" of the project you created last time as follows.
#qrscan: ^ 0.2.17 # Comment or delete existing packages qrscan: git: url: https://github.com/chandong83/qrcode_scanner.git ref: master
All you have to do is comment or delete the existing package (including version) and put your own github address in the form above.
Here, "ref" is the name of the commit of the source code. You can use this when using a specific commit. (However, it seems that you don't need to be a master.)
For detailed description of each item, please check the link below.
https://dart.dev/tools/pub/dependencies#git-packages
Package dependencies
Add other packages to your app. Specify package locations, version constraints, and more.
dart.dev
2. Apply the changed package
To apply the package with the changed location, use the following command.
flutter pub upgrade
If you haven't used the package before, you can import and use the package with "flutter pub get", but it will not be updated unless you upgrade because the same package was previously installed.
In other words, if the version or commit information has been changed, use "flutter pub upgrade" to download the new version again using "flutter pub upgrade".
3. Code Correction
Now let's remove the flash button.
Let's go to the path below from one Fork github.
qrcode_scanner / android / src / main / java / com / shinow / qrscan / SecondActivity.java
Now select "Edit this file" to edit the source code file directly.
Normally, you will download the source code and use it after modifying it, but it will be used for testing.
Find the onCreate function in the file editing screen and change the following parts as follows.
Before change
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); sensorEventListener = new LightSensorEventListener(lightLayout);
after
// sensorManager = (SensorManager) getSystemService (Context.SENSOR_SERVICE); // lightSensor = sensorManager.getDefaultSensor (Sensor.TYPE_LIGHT); // sensorEventListener = new LightSensorEventListener (lightLayout); lightLayout.setVisibility (View.INVISIBLE); //Add
There is a code that receives the value of the illuminance sensor from the source code and shows the flash button when it is dark and invisible when it is bright.
That's why this illuminance sensor event listener was blocked and the flash button was made invisible.
4. Package Update
Once again, let's apply the modified package with the package upgrade command.
flutter pub upgrade
You can also change the commit version to "pub get".
5. Execution result
Left: Before change, Right: After change When I used it ... I feel a little uncomfortable.
Personally, I think it would be easier to bring the package to the project and apply it.
Of course, if several people collaborate, this method may be right.
We will soon introduce how to import and modify packages into the project.
'Flutter > mobile' 카테고리의 다른 글
Flutter Back Button (0) 2020.05.13 Modifying the Flutter package-applied as an internal project (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 Create Flutter project in VSCode (0) 2020.05.12