This guide uses the current Ruflet API.
All widget builders are free helpers (text, row, column, etc.), not page.*.
require "ruflet"
Ruflet.run do |page|
app_name = "Hello"
page.title = app_name
body = column(
expand: true,
alignment: Ruflet::MainAxisAlignment::CENTER,
horizontal_alignment: Ruflet::CrossAxisAlignment::CENTER,
spacing: 8,
children: [
text(value: "Hello Ruflet", style: { size: 28 })
]
)
page.add(
body,
appbar: app_bar(title: text(value: app_name)),
floating_action_button: fab(
icon(icon: Ruflet::MaterialIcons::ADD),
on_click: ->(_e) {}
)
)
endThis is the current scaffold-style pattern:
appbar:for top barbodycontrol(s) inpage.add(...)floating_action_button:for primary action
Common page properties:
titleroutebgcolorvertical_alignmenthorizontal_alignment
Flet-style page centering:
class CenteredApp < Ruflet::App
def view(page)
page.title = "Centered"
page.vertical_alignment = Ruflet::MainAxisAlignment::CENTER
page.horizontal_alignment = Ruflet::CrossAxisAlignment::CENTER
page.add(text(value: "Hello World!", style: { size: 32 } ))
end
end
CenteredApp.new.runclass LayoutApp < Ruflet::App
def view(page)
page.add(
column(spacing: 12) do
text(value: "Line 1")
text(value: "Line 2")
end
)
end
endclass RowApp < Ruflet::App
def view(page)
page.add(
row(spacing: 8, alignment: "center") do
elevated_button(text: "Cancel")
elevated_button(text: "Save")
end
)
end
endclass ContainerApp < Ruflet::App
def view(page)
page.add(
container(width: 240, padding: 12, bgcolor: "#FFFFFF", border_radius: 10) do
text(value: "Card content")
end
)
end
endclass CenterWidgetApp < Ruflet::App
def view(page)
page.add(
center(content: text(value: "Centered"))
)
end
endclass ContentApp < Ruflet::App
def view(page)
page.add(
column(spacing: 10) do
text(value: "Title", style: { size: 24 , weight: "bold"})
text_field(label: "Name", width: 220)
elevated_button(text: "Primary")
end
)
end
endclass CounterApp < Ruflet::App
def initialize
super
@count = 0
end
def view(page)
counter = text(value: @count.to_s, size: 48)
page.add(
column(horizontal_alignment: "center", spacing: 8) do
text(value: "You clicked:")
counter
end,
floating_action_button: fab(Ruflet::MaterialIcons::ADD, on_click: ->(e) {
@count += 1
e.page.update(counter, value: @count.to_s)
})
)
end
end
CounterApp.new.runclass AppBarApp < Ruflet::App
def view(page)
page.add(
text(value: "Body"),
appbar: app_bar(
bgcolor: "#2196F3",
color: "#FFFFFF",
title: text(value: "My App")
),
floating_action_button: fab(
icon: icon(icon: Ruflet::MaterialIcons::ADD),
on_click: ->(_e) { puts "fab" })
)
end
endclass TabsApp < Ruflet::App
def view(page)
top_tabs = tabs(
expand: 1,
length: 3,
selected_index: 0,
content: column(
expand: true,
spacing: 0,
children: [
tab_bar(
tabs: [
tab(label: text(value: "Home")),
tab(label: text(value: "Play")),
tab(label: text(value: "About"))
]
),
tab_bar_view(
expand: 1,
children: [
container(expand: true, content: text(value: "Home tab")),
container(expand: true, content: text(value: "Play tab")),
container(expand: true, content: text(value: "About tab"))
]
)
]
)
)
bottom_tabs = navigation_bar(
selected_index: 0,
destinations: [
navigation_bar_destination(icon: icon(icon: Ruflet::MaterialIcons::HOME ), label: "Home"),
navigation_bar_destination(icon: icon(icon: Ruflet::MaterialIcons::HOME ), label: "Play"),
navigation_bar_destination(icon: icon(icon: Ruflet::MaterialIcons::SETTINGS ), label: "Settings")
]
)
page.add(
top_tabs,
appbar: app_bar(title: text(value: "Tabs Demo")),
navigation_bar: bottom_tabs
)
end
end- Use class-based apps for new projects and examples.
- Use
ruflet run main.rbto run your app.