(PRAC-8)Designing the mobile app to implement the state management.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
//_MyAppState createState() => _MyAppState();
State<MyApp> createState(){
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
//state of the widget
Color _containerColor = Colors.yellow;
void changeColor() {
setState(() {
if (_containerColor == Colors.yellow) {
_containerColor = Colors.green;
return;
}
_containerColor = Colors.yellow;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello World',
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(
title: Text('Hello'),
),
body: Container(color: _containerColor),
// ),
floatingActionButton: FloatingActionButton(onPressed: changeColor, child: Icon(Icons.add),tooltip: 'Click me',),
),
);
}
}
Comments
Post a Comment