(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

Popular posts from this blog

python(BI)

(PP-7)Create a class called Numbers, which has a single class attribute called MULTIPLIER, and a constructor which takes the parameters x and y (these should all be numbers). i. Write a method called add which returns the sum of the attributes x and y. ii. Write a class method called multiply, which takes a single number parameter a and returns the product of a and MULTIPLIER. iii. Write a static method called subtract, which takes two number parameters, b and c, and returns b - c. iv. Write a method called value which returns a tuple containing the values of x and y. Make this method into a property, and write a setter and a deleter for manipulating the values of x and y.