Maximum Minimum Number Between Multiple Numbers In Flutter

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

we have learn about finding max and min number between two numbers. But the main functionality every flutter dart developer needs is finding maximum and minimum number between multiple numbers from array.

Maximum Minimum Number Between Multiple Numbers In Flutter

Maximum Minimum Number Between Multiple Numbers
Complete Code For Maximum Minimum Number Between Multiple Numbers In Flutter
Main.dart

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

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

class MyApp extends StatelessWidget {
  int Number_c;
  findMinValue() {
    Number_c = [1, 2, 8, 6, 11, 15, 15, 22, 40].reduce(min);
    print(Number_c);
  }

  findMaxValue() {
    Number_c = [1, 2, 4, 7, 11, 15, 22, 32, 44].reduce(max);
    print(Number_c);
  }

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

Related Post