0% found this document useful (0 votes)
17 views2 pages

Flutter Widget Syntax

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Flutter Widget Syntax

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Flutter Widget Syntax

import 'package:flutter/[Link]';

class MyWidget extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Stateless Widget')),
body: Center(child: Text('Hello, Flutter!')),
);
}
}

void main() {
runApp(MaterialApp(home: MyWidget()));
}

import 'package:flutter/[Link]';

class MyStatefulWidget extends StatefulWidget {


@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {


int counter = 0;

void incrementCounter() {
setState(() {
counter++;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Stateful Widget')),
body: Center(
child: Column(
mainAxisAlignment: [Link],
children: [
Text('Counter: \$counter', style: TextStyle(fontSize: 24)),
SizedBox(height: 10),
ElevatedButton(
onPressed: incrementCounter,
child: Text('Increment'),
),
],
),
),
);
}
}

void main() {
runApp(MaterialApp(home: MyStatefulWidget()));
}

You might also like