1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

flutter webがrailsを乗る

Posted at

内容

flutter webで開発したfrontをrails serverでアクセルできるようにする手順

バージョン

flutter 2.0.1
rails 6.1.3

手順

  1. flutterをbuildする

flutter projectのフォルダで以下のcommandでbuildすると

flutter build web

フォルダbuild/webが作成される

  1. rails applicationを作成
rails new flutter-on-rails
rails g controller Home index

config/routes.rbを以下のように設定

Rails.application.routes.draw do
  root 'home#index'
end
  1. flutterのbuildしたファイルをrailsにcopy
  • flutter projectのフォルダbuild/web/assetsをrailsのapp/assets/下にcopy
  • flutter projectのフォルダbuild/web/iconsをrailsのapp/assets/下にcopy
  • flutterのbuildしたbuild/web/main.dart.jsファイルの内容をrailsのapp/javascript/packs/flutter.jsにcopy
  • flutterのファイルbuild/web/index.htmlの内容でrailsのapp/views/home/index.html.erbファイルを上書きする
  • railsのapp/views/home/index.html.erbファイルにflutter.jsの参照するようにする
<!DOCTYPE html>
<html>
<head>
  .......省略
  <link rel="manifest" href="manifest.json">
  <%= javascript_pack_tag "flutter" %>
</head>
  .......省略
  1. rails sでserverを起動する
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?