Flutter Project Make Simple Jokes App

 Flutter Project Make Simple Jokes App

Step 1 - Create A Flutter Project 

type - flutter create myapp

Step 2 - Remove All Default  Code 

Step 3 - Create Two Variables In _MyAppState Class

 // FOR CHANGE JOKES 
  var count = 0;
  // LIST OF JOKES
  var jokes = [
    'Learn programming to understand programming jokes.',
    'Code never lies,comments sometimes do.',
    'You are semicolons to my Statements',
    'Programming is 1% writing code and 99% understanding why its not working',
    'I told him I cound not open jar. He told me to download java',
    'Comparing java and javascript is same as comparing car and carpet',
    'Golden rule of programming - If it works dont touch it.'
  ];

Step 4 - Create a method for changes jokes

  // METHOD FOR CHANGE JOKES
  void increamentCount() {
    setState(() {
      if (count == jokes.length - 1) {
        count = 0;
      } else {
        count = count + 1;
      }
    });
  }

Step 5 - Design Your Material  App Body 


import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Keykey}) : super(keykey);

  @override
  State<MyAppcreateState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // FOR CHANGE JOKES 
  var count = 0;
  // LIST OF JOKES
  var jokes = [
    'Learn programming to understand programming jokes.',
    'Code never lies,comments sometimes do.',
    'You are semicolons to my Statements',
    'Programming is 1% writing code and 99% understanding why its not working',
    'I told him I cound not open jar. He told me to download java',
    'Comparing java and javascript is same as comparing car and carpet',
    'Golden rule of programming - If it works dont touch it.'
  ];
  // METHOD FOR CHANGE JOKES
  void increamentCount() {
    setState(() {
      if (count == jokes.length - 1) {
        count = 0;
      } else {
        count = count + 1;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title'Welcome to Flutter',
      homeScaffold(
        appBarAppBar(
          titleconst Text('My First Flutter Jokes App'),
          backgroundColorColors.pink,
        ),
        bodyContainer(
          decorationBoxDecoration(
            colorColors.pink[100],
            borderBorder.all(colorColors.black),
          ),
          marginEdgeInsets.all(20),
          paddingEdgeInsets.all(10),
          childText(
            jokes[count],
            styleTextStyle(fontSize20),
          ),
        ),
        floatingActionButtonFloatingActionButton(
          onPressedincreamentCount,
          childconst Icon(
            Icons.refresh,
            size50,
          ),
          backgroundColorColors.pink[700],
        ),
        floatingActionButtonLocationFloatingActionButtonLocation.centerFloat,
      ),
      debugShowCheckedModeBannerfalse,
    );
  }
}



Post a Comment

Previous Post Next Post