How to install Flutter on Ubuntu 20.10 and use it as a web server.
Installation of prerequisite software
sudo apt install clang curl pkg-config ninja-build cmake libblkid-dev libgtk-3-dev
Install Flutter
git clone https://github.com/flutter/flutter.git
Go to/usr/local/flutter
Set path
export PATH=$PATH:/usr/local/flutter/bin
Confirmation of installation
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.26.0-2.0.pre.220, on Linux, locale ja_JP.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 27.0.1)
✗ Flutter requires Android SDK 29 and the Android BuildTools 28.0.3
To update the Android SDK visit
https://flutter.dev/docs/get-started/install/linux#android-setup for
detailed instructions.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/linux#android-setup for
more details.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (2 available)
! Doctor found issues in 2 categories.
Software creation
flutter create myapp
cd myapp
Run as a web server (ports will be random)
$ flutter run -d web-server
Launching lib/main.dart on Web Server in debug mode...
Waiting for connection from debug service on Web Server... 25.3s
lib/main.dart is being served at http://localhost:42819
In the browser http://localhost:42819 To access
To start by specifying a port
flutter run -d web-server --web-port=1234
Modify the program. Replace lib/main.dart with:
lib/main.dart
import 'package:flutter/material.dart';
void main() {
runApp(ExampleApp());
}
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HelloWorld(),
);
}
}
class HelloWorld extends StatelessWidget {
@override
Widget build(BuildContext context) {
String str_out = 'Hello.\n';
str_out += 'It's sunny today.\n';
str_out += 'Jan/08/2021\n';
return Scaffold(
appBar: AppBar(
title: Text('Flutter Example App'),
),
body: Container(
alignment: Alignment.center,
child: Text(
str_out,
style: TextStyle(
fontSize: 70,
fontWeight: FontWeight.bold,
)
),
)
);
}
}
Start the server and access from the browser
Recommended Posts