Ubuntu에서 Flutter 사용

Ubuntu 20.10에 Flutter를 설치하여 웹 서버로 사용하는 방법입니다.

전제 소프트웨어 설치
sudo apt install clang curl pkg-config ninja-build cmake libblkid-dev libgtk-3-dev

Flutter 설치
git clone https://github.com/flutter/flutter.git

/usr/local/flutter로 이동

경로 설정
export PATH=$PATH:/usr/local/flutter/bin

설치 확인
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.6.0-12.0.pre.956, on Ubuntu 21.10
    5.13.0-22-generic, locale ja_JP.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      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/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)
[✓] VS Code (version 1.61.1)
[✓] Connected device (2 available)

! Doctor found issues in 2 categories.

버전 확인
$ flutter --version
Flutter 2.6.0-12.0.pre.956 • channel master • https://github.com/flutter/flutter
Framework • revision 704668406b (2 hours ago) • 2021-12-07 21:24:05 -0500
Engine • revision 66a281107b
Tools • Dart 2.16.0 (build 2.16.0-80.0.dev) • DevTools 2.9.1

소프트 만들기
flutter create myapp
cd myapp

웹 서버로 이동(포트는 무작위입니다)
$ 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

브라우저에서
http://localhost:42819
에 액세스


포트를 지정하고 시작하려면
flutter run -d web-server --web-port=1234

프로그램을 개조합니다.
lib/main.dart를 다음으로 바꿉니다.

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 = 'こんにちは。\n';
str_out += '今日は晴れています。\n';
str_out += 'Dec/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,
          )
        ),
      )
    );
  }
}

서버를 시작하고 브라우저에서 액세스

좋은 웹페이지 즐겨찾기