Currently, there are two different version of Java: java and java11. To check the version of both, you can use the following commands:
% brew info java
openjdk: stable 16.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
% brew info java11
openjdk@11: stable 11.0.10 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk@11.rb
License: GPL-2.0-only
Depending on your requirements, you can install one of the above. For me, some of the libraries I use in Dart are currently not compatible with the latest Java version (16.0.1), so I decided to install Java 11 with LTS (long term support).
% brew install java11
This will install Java version 11.0.10 as listed in the output above. The output also shows the following hints:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
For me it was necessary to called the specified command, so that the system finds the java binary:
Sometimes it’s necessary to trigger an action for CI/CD, e.g. when you use GitLab. To do this without any changes on the code base, you can create an empty commit. For this, git has a command:
When using nested Scaffolds (e.g. in combination with IndexedStack), the PrimaryScrollController is not usable by default. An IndexedStack will load all subviews so scroll-to-top will change all scrollable views at the same time, even if they are not visible or it simply does not work, because the PrimaryScrollController can only be attached to a single Scaffold.
To overcome this issue, the scrolls_to_top package can be used. This also works for nested Scaffolds. The functionality of the package is described in this post (here is the english translation).
The following code example shows the usage. This is how to use ScrollsToTop within each children of IndexedStack:
final _scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return Scaffold(
primary: true,
body: ScrollsToTop(
onScrollsToTop: (event) {
// onScrollsToTop will be called on each touch event, so check if the view is currently visible
if (!widget.isOnScreen) return;
_scrollController.animateTo(
event.to,
duration: event.duration,
curve: event.curve,
);
},
child: ListView.builder(
itemBuilder: _itemBuilder,
itemCount: 100,
controller: _scrollController,
),
),
);
}
By default, ReorderableListView only shows drag handles on desktop (GitHub). To enable a drag handle inside a ReorderableListView, it is possible to add the following code into the child’s subtree:
Most modern user interfaces are supporting different color schemes for day and night: the so called light and dark modes. Selecting a text color for each of those modes is not a big deal and it’s the way to go when designing the user interface.
In some cases, the text color is driven by the displayed contents. In the example below, the tint color is matched to the color of the drink. The global tint color of this app is totally different, but this color adjustment gives a very nice effect. But as you might already see, there is a small problem when it comes to very light or very dark colors: each color either has a good readability on light or dark backgrounds. Some colors might fit to both, but that’s not always the case. In the example below, the light yellow is still visible, but when it comes to small icons or small text, the details are lost.
To overcome this issue, a simple solution is to select two colors for each recipe so that each mode has a different one. That’s fine, but it might totally change the effect of this colored pages.
Can we calculate a suitable color?
Some time ago, there was an article about Black or white text on a colour background? In this one, I described different algorithms to calculate the best text color (black or white) for a colored background. But now, we need the opposite: a colored text that has a good readability on white (light) or black (dark) backgrounds.
When we look at HSL and HSV/HSB color models, we already have a value for ‘lightness’ or ‘brightness’. The idea is to find a color that matches a given hue and saturation and that has a brightness which is readable on light and dark background. For this, we can use different algorithms. Very good results could be achieved with a ‘Weighted W3C Formula‘. This formula take into consideration that the human eye perceives some of the primary colors darker than others.
f'(x) = r ? 0.299 + g ? 0.587 + b ? 0.11
Each color that is located at the border between the black and white overlay is suitable for light and dark backgrounds.
Step 1: convert the given color to HSV/HSB
Step 2: keep hue and saturation constant and adjust the brightness (make the color lighter or darker)
Step 3: convert the HSV/HSB value back to the required color format
Implementation in PHP
A simple calculation for a given RGB color is shown below. The classes used in this snippet are available on GitHub. The code checks the initial brightness of the color and lightens or darkens the values until the ‘border’ calculated by the ‘Weighted W3C Formula’ is reached. This is the case for the value 127, the total range of the brightness is 0 to 255.
But how does this result look for different colors? Let’s start with some dark colors. Those are fine for a light background, but they become unreadable on a dark one. The top colors show the input color (before) and the color below shows the output of the calculation above (after).
Color #632300 adjusted to be readable on light and dark background
Color #454545 adjusted to be readable on light and dark background
And now let’s look at some light colors which are fine for dark backgrounds, but they are totally unreadable on light backgrounds.
Color #73FEFF adjusted to be readable on light and dark background
Color #F0C&96 adjusted to be readable on light and dark background
The last color is similar to the example at the beginning and as you can see, the optimized color has a much better readability. This could be achieved for both light and dark colors. The code example shown above is written in PHP. An adoption should be easily possible for any other coding or scripting language
This will create a debug output and helps to track the tests:
In my case, this helped when my code reached an infinite loop due to an error. This results in a RuntimeException without any outputs or log messages. The process just ended with:
[Symfony\Component\Process\Exception\RuntimeException]
The process has been signaled with signal "11".