Last active
June 7, 2019 21:24
-
-
Save MaddieM4/d887da0843e114294f916360c2571042 to your computer and use it in GitHub Desktop.
Flutter scaffolding proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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