Author: David

Swtching Flutter from snap to native

Swtching Flutter from snap to native

Reinstalling Flutter on UbuntuA recent update saw Flutter compiles on Ubuntu broken due to an issue with lld. This was only on Flutter installed under snap. To fix it, I removed Flutter and reinstalled it from Git. There were a few issues after that so I’ve documented them here. This is the process.

First remove Flutter

sudo snap remove flutter

Then install it manually

cd ~

git clone https://github.com/flutter/flutter.git -b stable

Now modify .bashrc  (I prefer gedit but nano will do)

nano ~/.bashrc

Add this line at the end:

export PATH="$PATH:$HOME/flutter/bin"

Save it then do

source ~/.bashrc

Test the installation

flutter doctor

There may be some missing bits but this should fix them

sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev

and repeat flutter doctor until things are ok.

Now I still had some issues

Flutter doctor told me I had a different Dart installed.

So first remove the old one

sudo snap remove dart

Check with

which dart

My configuration still had the wrong dart in it. I searched these

cat /etc/environment 
cat ~/.profile 
cat ~/.bash_profile 
cat /etc/bash.bashrc 
grep -r "dart" ~/.bashrc ~/.bash_profile ~/.profile /etc/environment /etc/bash.bashrc 2
then did
echo $PATH

Which showed no dart references so

ls -la /usr/bin/dart
which dart
sudo apt remove dart

which dart
dart --version
flutter doctor

I then found that it was trying to use a snap version of cmake

cd your_project
flutter clean
rm -rf build/
rm -rf linux/build/

and removed Cmake cache files

rm -rf linux/flutter/ephemeral/
rm linux/CMakeCache.txt 2>/dev/null

Finally I regenerated the build configuration

flutter pub get
flutter config --enable-linux-desktop
flutter create

and all was well and after adding the correct SDK path into the project files, it finally compiled on Linux again. Phew!

The perils of updates

The perils of updates

Target dart_build failed: Error: Failed to find any of [ld.lld, ld] in LocalDirectory: '/snap/flutter/149/usr/lib/llvm-10/bin' So I’ve been working on my game and to save time build the web project as a Linux app. It compiles it and runs it quicker than doing it with Chrome.  Until yesterday.

After doing the usual sudo apt update and then upgrade, and snap refresh.I had updated Flutter (and Dart)  and afterwards, upgraded all of the pubspec.yaml and finally ran Flutter Doctor.  It output this

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.7, on Ubuntu 24.04.3 LTS 6.14.0-37-generic, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
    ✗ cmdline-tools component is missing.
      Try installing or updating Android Studio.
      Alternatively, download the tools from https://developer.android.com/studio#command-line-tools-only and make sure to set the ANDROID_HOME environment variable.
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/linux-android-setup for more details.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.

I’m not worried about Android so Linux and Chrome were fine; everything is up to date.  Until I tried to run the app (as Linux) and got the message at the top. It says

ERROR: Target dart_build failed: Error: Failed to find any of [ld.lld, ld] in LocalDirectory: 
'/snap/flutter/149/usr/lib/llvm-10/bin'

I can still run it as a Chrome web app so it’s not the end of the world; more a speed bump than a road block but still annoying. I looked up the error but there was nothing really helpful. Installing lld did not fix it.

I asked an AI (Chrome what I could do and it have me three alternatives).

  1. Install a symbolic link to lld but that failed as the area is read only. Even with sudo.
  2. Refresh from a different snap channel but even with a full reboot after doing that it made no difference.
  3. Suggests uninstalling Flutter from snap and install it manually, so that’s what I guess I have to do.

What a faff!

Theming in Flutter – FlexColorScheme

Theming in Flutter – FlexColorScheme

FlexColorScheme playground screenshotOne of Flutter’s big strengths is its supports for theming;  you can define or change colours for every aspect of your UI but it can be a bit complicated. Now an open source project provides a way to simplify things. It’s called FlexColorScheme and is just superb.

The image shows the playground where you can pick a scheme and see how the controls look.

The documentation includes an indepth look at theming. The FlexColorScheme is a Flutter widget and there’s link to the source code on GitHub.  It is highly recommended.

Linux challenges with the Flutter game

Linux challenges with the Flutter game

Tux and Flutter having a tussle
Generated by Gemini

The architecture of this is all Flutter and Dart running on a Ubuntu Linux box. There are two pure Dart programs- one to create the game setup and one to do the processing. The first is run manually, the second by crontab. Then there’s the Flutter web app.

The Flutter web app has to read and write files from the file system which of course it can’t do directly. I’ve created a backend of sorts using PHP.  There’s an API; it works but not without issues. If you’re calling a PHP script from a Flutter app, what is the URL?  It depends.

Say the URL is /file?params where I’ve modified .htaccess to pass /file urls onto a PHP script.

If I want to test this on the box in a browser I have to call localhost/file?params but in a Dart program running on the box it just calls /file?params.

The next problem is where are the game files stored. The setup program doesn’t really care. Any location will do so long as it doesn’t need to run elevated.  But the web app is limited to /var/www/html – it’s running under Apache on a linux box. In the end I created a folder under /var/www/game and each game is stored under there. PHP can read mostly anywhere, not just in /var/www/html and this provide a little extra security.

However there’s the not-so slight issue of permissions. The setup program runs under my login – call it user. So files are created owned by user user. The web app runs under www-data so to keep things simple, I’ve set permissions to user:www-data so both can access it. It’s a bit of a faff.

Here’s a tip. If you are developing a Flutter web app, develop it on Linux and do development as a Linux app. It’s far quicker building and launching a Linux app than it is the web app.

 

 

 

A silly bug in Flutter/Dart

A silly bug in Flutter/Dart

Robot postman
Generated by Gemini

So I’m developing a web postal* game client which is loaded from a Linux server as a Flutter web app. When I run it on the Linux box from Chromium, no problems, it loads a binary file ok. When I try to run it from a networked Windows box, the binary file fails to load. It’s loaded by calling a PHP endpoint, passing the path of the file to a PHP script.

It was my fault. Because the game client is loaded from the Linux server and the path is a Linux path to the binary file, I’d missed that it runs on the Windows box (where the browser launches from). I’d used Platform.isLinux and Platform.Windows calls to figure out the path when I initially tested it on a Windows box.  The path to the binary file was being sent as if the file was on the Windows box because the Flutter app runs as JavaScript in the browser there. D’oh!

*Postal means a game where the game client sends orders to the server. Those are processed once an hour and the results file is picked up when the client next runs. It’s how games used to be played through the post back 30 or 40 years ago hence the name. 

 

Fun with Flutter

Fun with Flutter

So I upgraded Flutter to 3.35 and tried building an app for the Web. It failed with a weird error about the js package being deprecated. Errors a bit like this:

Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
Error: Couldn’t resolve the package ‘libphonenumber_web’ in ‘package:libphonenumber_web/libphonenumber_web.dart’.
.dart_tool/flutter_build/6872c759b3585597f59b4a698a13ca94/web_plugin_registrant.dart:9:8:
Error: Not found: ‘package:libphonenumber_web/libphonenumber_web.dart’
import ‘package:libphonenumber_web/libphonenumber_web.dart’;

I’d been experimenting with flutter_login package and it was in the projects pubspec.yaml.  I found this out by using this command:

flutter pub deps

Which provides a full and detailed tree of all package dependencies. Like this but 260 lines in total!

turfwar 1.0.0+1
|– badges 3.1.2
| ‘– flutter…
|– cupertino_icons 1.0.8
|– flutter 0.0.0
| |– characters 1.4.0
| |– collection 1.19.1
| |– material_color_utilities 0.11.1
| | ‘– collection…
| |– meta 1.16.0
| |– sky_engine 0.0.0
| ‘– vector_math 2.2.0
|– flutter_lints 6.0.0
| ‘– lints 6.0.0
|– flutter_test 0.0.0

js was used by libphonenumber which was part of flutter_login.  However despite removing that from pubspec.yaml and removing the package files, the flutter build web command was still complaining about it.

The trick to solving that is just to delete the .dart_tool folder. It’s regenerated by the flutter build command so is safe to delete.

Flutter project screenshot

There’s a new feature now, you can add –wasm on the end of the flutter build web command to have it use wasm. More on this official flutter wasm page which includes a link to a neat demo project called wonderous that is worth a look; the source to that is available on GitHub as well..

Great mystery #1 solved!

Great mystery #1 solved!

It was kind of silly. I installed Debian 13 in hyper-V, just to see how different it is from Ubuntu.  Like Ubuntu, it starts in a default size. I looked in the settings and there was a Displays there so I tried it and got the screen resized to full screen size.

So I then went back to Ubuntu and tried that, and it worked. I believe that what helped was having guest services ticked in the Hyper-v settings.

Hyper-V settings Display settings in Ubuntu

Great mysteries – number 1

Great mysteries – number 1

Hyper-v that refuses to become fullscreen!I run Ubuntu in a hyper-V session.  It works very well and handy for getting screenshots. I’ve been using a 24.04 LTS for a while and decided I needed another one to test CyberPanel. i already have Webmin on my main one so wanted a clean Ubuntu so as not to mess Webmin.  It took ten minutes to setup then another 20 minutes to install 300+ updates.

Then I edited Grub to give me a fullscreen- 1920 x 1080.  You just edit /etc/default/grub with an editor run under sudo. I use Gedit but nano will do. Just change the line to this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1920x1080"

followed by

sudo update-grub

and that should be it. Only it didn’t work in my new Ubuntu 24.04 LTS VM. I installed ifconfig from net-tools, connected to it from my Windows PC and copied grub across. I did the same with my older 24.04 LTS VM and compared the two grub files. Both identical yet one works fullscreen and the newer one doesn’t. Any ideas?

Don’t get Flutter and Dart mixed up

Don’t get Flutter and Dart mixed up

A bird a Flutter and Darts

I’m working on a game with a Flutter web client and two Dart terminal programs hence the visual pun. Annoyingly, you can’t compile a Dart exe for Linux on a Windows PC. You can do that in C# but I prefer to use Dart.

I have all the classes in two files (one is called classes.dart) and because I’m using JSON to persist game data, I use the build_runner package from pub.dev. Just add this before any classes:

@JsonSerializable()

Make sure if you have enums that every enum value has

@JsonValue('houses')

before it and add functions like this for each class you want to persist; in this case a Location class:

factory Location.fromJson(Map<String, dynamic> json) =>
    _$LocationFromJson(json);

Map<String, dynamic> toJson() => _$LocationToJson(this);

Then when it’s all done, do this to generate a file that handles loading and saving the specified classes.

dart run build_runner build

Along the way though I managed to get Flutter into a Dart program. I’m using SQLite but only in Dart, not in the Flutter app. Unfortunately I used the kIsWeb constant to exclude some calls (when the classes are used by the Flutter app) in my classes file.  But you can’t do that in a pure Dart program, it will not compile. Instead I wrote my own function.

bool isWeb() {
  return !Platform.isWindows && !Platform.isLinux;
}

Interestingly, the definition of kIsWeb in the API is this below, so it might be worth trying that out.

const bool kIsWeb = bool.fromEnvironment(‘dart.library.js_util’);

Ever do a sudo apt update on your Raspberry Pi?

Ever do a sudo apt update on your Raspberry Pi?

sudo apt update error message

 

 

 

 

And you get this error message?  It says

E: Release file for http://archive.raspberrypi.com/debian/dists/bookworm/InRelease is not valid yet 
(invalid for another 10h 37min 50s). Updates for this repository will not be applied.
E: Release file for http://deb.debian.org/debian/dists/bookworm-updates/InRelease is not valid yet 
(invalid for another 12h 15min 47s). Updates for this repository will not be applied.

If you do

sudo hwclock -s

It will fix it. Apparently it’s to do with the hardware clock having drifted and I’m guessing this causes an error condition. Still, its an easy fix!