Find Maximum Number Value Between Two Numbers In Flutter

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

In Flutter there is a inbuilt function of ‘dart:math’ library which named as max<T extends num> function. This function is used in Flutter to find out Maximum number between given two integer type numbers. The max() function would automatically calculate both two values and in return it will give us the max number. We would also store the max number in integer variable and then use it again as per our requirement.

Find Maximum Number Value Between Two Numbers In Flutter

Maximum Number Value Between Two Numbers
Complete Code For Maximum Number Value Between Two Numbers In Flutter
Main.dart

import 'package:flutter/material.dart';
import 'dart:math';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  int Number_A = 220;
  int Number_B = 330;
  int Number_C;

  findMaxBetweenTwoValues() {
    Number_C = max(Number_A, Number_B);
    print(Number_C);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.lightGreen,
            title: Text("Maximum Value Between 2 Numbers"),
          ),
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                          margin: const EdgeInsets.fromLTRB(20, 10, 20, 10),
                          child: RaisedButton(
                            onPressed: () => findMaxBetweenTwoValues(),
                            child: Text(' Find Maximum Value Between 2 Numbers '),
                            textColor: Colors.white,
                            color: Color(0xFFFFC107),
                            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                          )),
                    ]
                )
            )
        )
    );
  }
}

Related Post