Dart Find Max Number Value Between Two Numbers In Flutter

admin_img Posted By Bajarangi soft , Posted On 10-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.

Dart Find Max Number Value Between Two Numbers In Flutter

Find Max Number Value Between Two Numbers
Complete Code For Max 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 Number1 = 15;
  int Number2 = 30;
  int Number3;

  findMaxBetween2Values() {
    Number3 = max(Number1, Number2);
    print(Number3);
  }

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

Related Post