Skip to content

Instantly share code, notes, and snippets.

@MaddieM4
Last active June 7, 2019 21:24
Show Gist options
  • Save MaddieM4/d887da0843e114294f916360c2571042 to your computer and use it in GitHub Desktop.
Save MaddieM4/d887da0843e114294f916360c2571042 to your computer and use it in GitHub Desktop.
Flutter scaffolding proposal
import "github.com/flutter/flutter"
import . "scaffold" // scaffold.go
func (m *MyHomePage) Build(ctx flutter.BuildContext) flutter.Widget {
return Scaffold{
AppBar: AppBar{
Title: Text{ Text: "My Home Page"},
},
Body: Center{
Child: Column{
MainAxisAlignment: MainAxisAlignment.center,
Children: []Widget{
Text{ Text: "You have pushed the button this many times:" },
Text(
Text: fmt.Sprintf("%d", m.counter),
Style: ctx.textTheme.display1,
},
}
}
},
FloatingActionButton: FloatingActionButton{
onPressed: m.incrementCounter,
Tooltip: "Increment",
Child: Icon{Icons.add}, // Couldn't resist just one shorthand :)
}
}.Construct()
}
import "github.com/flutter/flutter"
type Widget interface {
Construct() flutter.Widget
}
type Text struct {
Text string
Style // ... whatever this is, I'm example-ing
}
func (t *Text) Construct() {
return flutter.Text(t.Text, t.Style)
}
type Column struct {
MainAxisAlignment: ...
Children []Widget
}
func (c *Column) Construct() {
// Example of recursive construction for container widgets
children = make([]flutter.Widget, len(c.Children))
for i, child := range c.Children {
children[i] = child.Construct()
}
return flutter.Column(c.MainAxisAlignment, children)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment