0% found this document useful (0 votes)
42 views3 pages

Mobile Application Development (Assignment)

This document contains code for a Flutter mobile app that displays a counter. It includes a StatefulWidget class called _MyHomePageState that manages the counter state. The counter is initialized to 0. There are increment and decrement methods that use setState to update the counter. The build method returns a Scaffold with an AppBar, center column displaying the counter, and a row of floating action buttons to increment and decrement the counter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Mobile Application Development (Assignment)

This document contains code for a Flutter mobile app that displays a counter. It includes a StatefulWidget class called _MyHomePageState that manages the counter state. The counter is initialized to 0. There are increment and decrement methods that use setState to update the counter. The build method returns a Scaffold with an AppBar, center column displaying the counter, and a row of floating action buttons to increment and decrement the counter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name M.

Shehzad Ali Khan


Roll-Number NIM-BSCS-2019-68
Course-Name Mobile App Development

Question:
Add and Subtract button to increment and decrement …

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Assignment One',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
 }
}
class MyHomePage extends StatefulWidget {

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
 }
  void _decrementorf() {
    setState(() {
      _counter--;
    });
 }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.deepOrangeAccent,
        title: Center(child: Text('Add and Sub Counter')),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the this Button many times:',
            ),
            Text(
              '$_counter',
              style: Theme
                  .of(context)
                  .textTheme
                  .headlineMedium,

            ),

          ],
        ),
      ),
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          FloatingActionButton(
            onPressed: _decrementorf,
            tooltip: 'Decrement',
            child: const Icon(Icons.remove),
          ),
          const SizedBox(width: 235),
          FloatingActionButton(
            onPressed: _incrementCounter,
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        ],
      ),

    );
 }
}

-------------------------------------------------------------

You might also like