0% found this document useful (0 votes)
6 views

Flutter

This Flutter code defines a StatefulWidget class called MyHomePage that contains a counter variable and increment method. The build method returns a Scaffold with AppBar, Center child and floating action button to increment the counter.

Uploaded by

wafer123456789
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Flutter

This Flutter code defines a StatefulWidget class called MyHomePage that contains a counter variable and increment method. The build method returns a Scaffold with AppBar, Center child and floating action button to increment the counter.

Uploaded by

wafer123456789
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import 'package:flutter/material.

dart';

class MyHomePage extends StatefulWidget {


const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {

_counter++;
});
}
@override
Widget build(BuildContext context) {

return Scaffold(
backgroundColor: Colors.pinkAccent,
appBar: AppBar(

//backgroundColor:
Theme.of(context).colorScheme.inversePrimary,

title: Text(widget.title),
),
body: Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}

You might also like