Skip to content

Instantly share code, notes, and snippets.

@alin-turcu
Last active July 13, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alin-turcu/38b25e1469e4897e7d7b1aedb3fd2e8a to your computer and use it in GitHub Desktop.
Save alin-turcu/38b25e1469e4897e7d7b1aedb3fd2e8a to your computer and use it in GitHub Desktop.
jetpack vs SwiftUi
class MyApp extends State<MyHomePage> {
int count = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Column(children: <Widget>[
Text('count $count',),
FlatButton(child: Text("Increment",), onPressed: () { setState(() { count++; });}),
FlatButton(child: Text("Decrement",), onPressed: () { setState(() { count--; });}),
]));
}
}
@Composable
fun AppBody() {
val count = +state { 0 }
Center {
Column {
Text("count: ${count.value}")
Button("Increment", onClick = { count.value++ })
Button("Decrement", onClick = { count.value-- })
}
}
}
struct AppBody : View {
@State var count = 0
var body: some View {
VStack {
Text("count: \(count)")
Button("Increment") { self.count += 1 }
Button("Decrement") { self.count -= 1 }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment