QuickSort & Sum is a ready-to-use widget for calculating algorithms

Related tags

Widgets algorithms
Overview

Flutter Algorithm

pub package

This design is for an algorithm design lesson.

QuickSort & Sum is a ready-to-use widget for calculating algorithms. Shows the capabilities of the filter

Examples

Basic example quickSort algorithm

int.parse(e)).toList(); int high = result.length - 1; int low = 0; finalResult = quickSort(result, low, high); print(finalResult); String exit = "لیست اعداد مرتب شده: " + finalResult.toString(); Alert( context: context, title: "لیست اعداد مرتب شده", type: AlertType.success, desc: finalResult.toString(), style: const AlertStyle( alertElevation: 5.0, descStyle: TextStyle( fontWeight: FontWeight.w500, fontSize: 18, fontFamily: 'IRANSANS')), buttons: [ DialogButton( child: const Text( 'تایید', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), ), onPressed: () { setState(() { number.clear(); result.clear(); }); Navigator.of(context).pop(); }), ]).show(); }); }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Colors.green[700]), width: MediaQuery.of(context).size.width - 50, height: 50, child: const Center( child: Text( "برای مرتب سازی اعداد اینجا بزنید", style: TextStyle( fontWeight: FontWeight.bold, color: Colors.white, fontSize: 18), )), ), ), ), ) ], ), ), ), ))); } List quickSort(List list, int low, int high) { if (low < high) { int pi = partition(list, low, high); quickSort(list, low, pi - 1); quickSort(list, pi + 1, high); } return list; } int partition(List list, low, high) { // Base check if (list.isEmpty) { return 0; } // Take our last element as pivot and counter i one less than low int pivot = list[high]; int i = low - 1; for (int j = low; j < high; j++) { // When j is < than pivot element we increment i and swap arr[i] and arr[j] if (list[j] < pivot) { i++; swap(list, i, j); } } // Swap the last element and place in front of the i'th element swap(list, i + 1, high); return i + 1; } // Swapping using a temp variable void swap(List list, int i, int j) { int temp = list[i]; list[i] = list[j]; list[j] = temp; } }">
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';

class QuickSortAlgorithmScreen extends StatefulWidget {
  const QuickSortAlgorithmScreen({Key? key}) : super(key: key);

  @override
  _AlgorithmHomeScreenState createState() => _AlgorithmHomeScreenState();
}

class _AlgorithmHomeScreenState extends State<QuickSortAlgorithmScreen> {
  List<String> number = [];
  List<int> result = [];
  List<int> finalResult = [];

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Directionality(
            textDirection: TextDirection.rtl,
            child: Scaffold(
              resizeToAvoidBottomInset: false,
              appBar: AppBar(
                title: const Text(
                  "الگوریتم مرتب سازی سریع",
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                ),
                centerTitle: true,
                backgroundColor: const Color(0xFF1A374D),
              ),
              backgroundColor: const Color(0xFFF7F7F7),
              body: SingleChildScrollView(
                reverse: true,
                child: Form(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Padding(
                        padding: EdgeInsets.only(top: 30, right: 10, left: 10),
                        child: Text(
                          "مساله:\n       مرتب سازی عناصر آرایه s از کوچیک به بزرگ",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(top: 30, right: 10, left: 10),
                        child: Text(
                          "ورودی ها:\n         آرایه s",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(
                            top: 30, right: 10, left: 10, bottom: 20),
                        child: Text(
                          "خروجی ها:\n            مرتب شده ارایه s",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                        ),
                      ),
                      const Center(
                        child: Text(
                          "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(
                            top: 30, right: 10, left: 10, bottom: 10),
                        child: Text(
                          "زبان های استفاده شده برای طراحی نرم افزار:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                        ),
                      ),
                      const Center(
                        child: Text(
                          "دارت( DART ) و فلاتر ( FLUTTER )",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 18),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(
                            top: 30, right: 10, left: 10, bottom: 10),
                        child: Text(
                          "طراحی شده توسط:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 15),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(bottom: 20),
                        child: Center(
                          child: Text(
                            "علی مشکانی / رضا صومعه",
                            style: TextStyle(
                                fontWeight: FontWeight.bold, fontSize: 18),
                          ),
                        ),
                      ),
                      const Center(
                        child: Text(
                          "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                      ),
                      const Padding(
                        padding:
                        EdgeInsets.only(top: 30, right: 10, bottom: 15),
                        child: Text(
                          "لیست اعداد را طبق نمونه وارد کنید:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 20),
                        ),
                      ),
                      // input button for create array
                      Container(
                          margin: const EdgeInsets.symmetric(horizontal: 15),
                          padding: const EdgeInsets.symmetric(horizontal: 10),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(5),
                              border: const Border(
                                bottom:
                                BorderSide(width: 0.5, color: Colors.black),
                                top:
                                BorderSide(width: 0.5, color: Colors.black),
                                left:
                                BorderSide(width: 0.5, color: Colors.black),
                                right:
                                BorderSide(width: 0.5, color: Colors.black),
                              )),
                          child: TextFormField(
                            keyboardType: TextInputType.number,
                            onChanged: (value) {
                              number = value.split(",");
                              //print(number.runtimeType);
                            },
                            textDirection: TextDirection.ltr,
                            decoration: const InputDecoration(
                                hintText: "مثال: 1,5,3,2,4",
                                border: InputBorder.none,
                                labelText: 'لیست اعداد'),
                          )),
                      Padding(
                        padding: const EdgeInsets.only(top: 60, bottom: 30),
                        child: Center(
                          child: GestureDetector(
                            onTap: () {
                              setState(() {
                                result =
                                    number.map((e) => int.parse(e)).toList();
                                int high = result.length - 1;
                                int low = 0;
                                finalResult = quickSort(result, low, high);
                                print(finalResult);
                                String exit = "لیست اعداد مرتب شده:  " + finalResult.toString();
                                Alert(
                                    context: context,
                                    title: "لیست اعداد مرتب شده",
                                    type: AlertType.success,
                                    desc: finalResult.toString(),
                                    style: const AlertStyle(
                                        alertElevation: 5.0,
                                        descStyle: TextStyle(
                                            fontWeight: FontWeight.w500,
                                            fontSize: 18,
                                            fontFamily: 'IRANSANS')),
                                    buttons: [
                                      DialogButton(
                                          child: const Text(
                                            'تایید',
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                fontSize: 18,
                                                color: Colors.white),
                                          ),
                                          onPressed: () {
                                            setState(() {
                                              number.clear();
                                              result.clear();
                                            });
                                            Navigator.of(context).pop();
                                          }),
                                    ]).show();
                              });
                            },
                            child: Container(
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(10),
                                  color: Colors.green[700]),
                              width: MediaQuery.of(context).size.width - 50,
                              height: 50,
                              child: const Center(
                                  child: Text(
                                    "برای مرتب سازی اعداد اینجا بزنید",
                                    style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        color: Colors.white,
                                        fontSize: 18),
                                  )),
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            )));
  }

  List<int> quickSort(List<int> list, int low, int high) {
    if (low < high) {
      int pi = partition(list, low, high);
      quickSort(list, low, pi - 1);
      quickSort(list, pi + 1, high);
    }
    return list;
  }

  int partition(List<int> list, low, high) {
    // Base check
    if (list.isEmpty) {
      return 0;
    }
    // Take our last element as pivot and counter i one less than low
    int pivot = list[high];

    int i = low - 1;
    for (int j = low; j < high; j++) {
      // When j is < than pivot element we increment i and swap arr[i] and arr[j]
      if (list[j] < pivot) {
        i++;
        swap(list, i, j);
      }
    }
    // Swap the last element and place in front of the i'th element
    swap(list, i + 1, high);
    return i + 1;
  }

// Swapping using a temp variable
  void swap(List list, int i, int j) {
    int temp = list[i];
    list[i] = list[j];
    list[j] = temp;
  }
}

Basic example sum algorithm

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

class SumAlgorithmScreen extends StatefulWidget {
  const SumAlgorithmScreen({Key? key}) : super(key: key);

  @override
  _SumAlgorithmScreenState createState() => _SumAlgorithmScreenState();
}

class _SumAlgorithmScreenState extends State<SumAlgorithmScreen> {
  late String numbers;
  List number = [];
  int result = 0;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Directionality(
          textDirection: TextDirection.rtl,
          child: Scaffold(
            resizeToAvoidBottomInset: false,
            appBar: AppBar(
              title: const Text(
                "الگوریتم جمع عناصر آرایه",
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
              ),
              backgroundColor: const Color(0xFF1A374D),
              centerTitle: true,
            ),
            backgroundColor: const Color(0xFFF7F7F7),
            body: SingleChildScrollView(
              reverse: true,
              child: Form(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Padding(
                      padding: EdgeInsets.only(top: 30, right: 10, left: 10),
                      child: Text(
                        "مساله:\n          تمام اعداد موجود در آرایه n عنصری S را باهم جمع کنید.",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                      ),
                    ),
                    const Padding(
                      padding: EdgeInsets.only(top: 30, right: 10, left: 10),
                      child: Text(
                        "ورودی ها:\n          عدد صحیح و مثبت n آرایه S با اندیس 0 تا n",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                      ),
                    ),
                    const Padding(
                      padding:
                      EdgeInsets.only(top: 30, right: 10, left: 10, bottom: 20),
                      child: Text(
                        "خروجی ها:\n          sum، حاصل جمع اعداد موجود در آرایه S",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                      ),
                    ),
                    const Center(
                      child: Text(
                        "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                    ),
                    const Padding(
                      padding:
                      EdgeInsets.only(top: 30, right: 10, left: 10, bottom: 10),
                      child: Text(
                        "زبان های استفاده شده برای طراحی نرم افزار:",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                      ),
                    ),
                    const Center(
                      child: Text(
                        "دارت( DART ) و فلاتر ( FLUTTER )",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
                      ),
                    ),
                    const Padding(
                      padding:
                      EdgeInsets.only(top: 30, right: 10, left: 10, bottom: 10),
                      child: Text(
                        "طراحی شده توسط:",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
                      ),
                    ),
                    const Padding(
                      padding: EdgeInsets.only(bottom: 20),
                      child: Center(
                        child: Text(
                          "علی مشکانی / رضا صومعه",
                          style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
                        ),
                      ),
                    ),
                    const Center(
                      child: Text(
                        "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                    ),
                    const Padding(
                      padding: EdgeInsets.only(top: 30, right: 10, bottom: 15),
                      child: Text(
                        "لیست اعداد را طبق نمونه وارد کنید:",
                        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                      ),
                    ),
                    // input button for create array
                    Container(
                        margin: const EdgeInsets.symmetric(horizontal: 15),
                        padding: const EdgeInsets.symmetric(horizontal: 10),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(5),
                            border: const Border(
                              bottom: BorderSide(width: 0.5, color: Colors.black),
                              top: BorderSide(width: 0.5, color: Colors.black),
                              left: BorderSide(width: 0.5, color: Colors.black),
                              right: BorderSide(width: 0.5, color: Colors.black),
                            )),
                        child: TextFormField(
                          keyboardType: TextInputType.number,
                          onChanged: (value) {
                            setState(() {
                              numbers = value;
                              number = numbers.split(",");
                              result = 0;
                            });
                          },
                          textDirection: TextDirection.ltr,
                          decoration: const InputDecoration(
                              hintText: "مثال: 1,2,3,4",
                              border: InputBorder.none,
                              labelText: 'لیست اعداد'),
                        )),
                    // Button for calculate the sum of numbers inside an array
                    Padding(
                      padding: const EdgeInsets.only(top: 60, bottom: 30),
                      child: Center(
                        child: GestureDetector(
                          onTap: () {
                            // الگوریتم محاسبه جمع اعداد داخل آرایه ورودی
                            for (int i = 0; i < number.length; i++) {
                              setState(() {
                                result = result + int.parse(number[i]);
                              });
                            }
                            // ---------------------------------------------
                            Alert(
                                context: context,
                                type: AlertType.success,
                                title: "لیست آرایه ورودی \n $number",
                                desc: "مجموع عناصر آرایه:     $result",
                                style: const AlertStyle(
                                    alertElevation: 5.0,
                                    descStyle: TextStyle(
                                        fontWeight: FontWeight.w500,
                                        fontSize: 18,
                                        fontFamily: 'IRANSANS')),
                                buttons: [
                                  DialogButton(
                                      child: const Text(
                                        'تایید',
                                        style: TextStyle(
                                            fontWeight: FontWeight.bold,
                                            fontSize: 18,
                                            color: Colors.white),
                                      ),
                                      onPressed: () {
                                        setState(() {
                                          numbers = '';
                                          number.clear();
                                          result = 0;
                                        });
                                        Navigator.of(context).pop();
                                      }),
                                ]).show();
                          },
                          child: Container(
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(10),
                                color: Colors.green[700]),
                            width: MediaQuery.of(context).size.width - 50,
                            height: 50,
                            child: const Center(
                                child: Text(
                                  "برای محاسبه جمع اینجا بزنید",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      color: Colors.white,
                                      fontSize: 18),
                                )),
                          ),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          ),
        ));
  }
}

License

  • AM Licence
You might also like...

Full customable rolling switch widget for flutter apps based on Pedro Massango's 'crazy-switch' widget

Full customable rolling switch widget for flutter apps based on Pedro Massango's 'crazy-switch' widget

lite_rolling_switch Full customable rolling switch widget for flutter apps based on Pedro Massango's 'crazy-switch' widget https://github.com/pedromas

Dec 1, 2022

Progress Dialog widget for flutter projects with ability to customize loading widget, background color and background blur.

Progress Dialog widget for flutter projects with ability to customize loading widget, background color and background blur.

DISCONTINUED Checkout ArsDialog ars_progress_dialog Customizable progress dialog for Flutter applications with smooth animation for background dim col

Apr 15, 2022

A Flutter widget that will give a Glitch Animation Effect to it's child widget.

A Flutter widget that will give a Glitch Animation Effect to it's child widget.

GlitchEffect A Flutter widget that will give a Glitch Animation Effect to it's child widget. Installation Add the latest version of package to your pu

Nov 25, 2022

Flutter Triple Status Button can use toggle button but in three statuses.

Flutter Triple Status Button can use toggle button but in three statuses.

triple_status_button Triple Status Button. Flutter Triple Status Button can use toggle button but in three statuses. Property Description height heigh

Nov 13, 2021

A Flutter plugin to use Chrome Custom Tabs.

Flutter Custom Tabs Plugin With the Flutter Custom Tabs Plugin, you can use Custom Tabs as easily as url_launcher. This plugin is built as federated p

Nov 18, 2022

A really easy to use flutter toast library

A really easy to use flutter toast library

BotToast 🤖 A really easy to use flutter toast library! Language: English | 中文简体 🐲 Overview 🐼 Online Demo 🐳 Example 🐺 Renderings 🐮 Getting starte

Dec 28, 2022

RFlutter Alert is super customizable and easy-to-use alert/popup dialogs for Flutter.

RFlutter Alert is super customizable and easy-to-use alert/popup dialogs for Flutter.

RFlutter Alert is super customizable and easy-to-use alert/popup dialogs for Flutter. You may create reusable alert styles or add buttons as much as you want with ease.

Jan 1, 2023

A package for flutter to use alert and toast within one line code.

A package for flutter to use alert and toast within one line code.

easy_alert A package for flutter to use alert and toast within one line code. Getting Started Add easy_alert: to your pubspec.yaml, and run flutt

Jun 25, 2021

A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate

A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate

A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.

Dec 13, 2022
Owner
Ali Mashkani
Andriod Developer
Ali Mashkani
Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.

sticky_and_expandable_list Flutter implementation of sticky headers and expandable list.Support use it in a CustomScrollView. README i18n:中文说明 Feature

tp7309 114 Nov 16, 2022
A popup simple topModalSheet menu button widget with handsome design and easy to use

top_modal_sheet A popup simple topModalSheet menu button widget with handsome design and easy to use. Installations Add top_modal_sheet: ^1.0.0 in you

Baldemar Alejandres 5 Jul 29, 2022
Flutter Color Picker Wheel - an easy to use widget which can be heavily customized

Flutter Color Picker Wheel Flutter Color Picker Wheel is an easy to use widget which can be heavily customized. You can use the WheelColorPicker direc

Kexin Lu 35 Oct 4, 2022
Flutter ColorFilter generator and presets to use with ColorFiltered widget.

Flutter ColorFilter generator and presets to use with ColorFiltered widget.

null 2 Jun 7, 2022
A simple Flutter widget to add in the widget tree when you want to show nothing, with minimal impact on performance.

nil A simple widget to add in the widget tree when you want to show nothing, with minimal impact on performance. Why? Sometimes, according to a condit

Romain Rastel 127 Dec 22, 2022
A flutter carousel widget, support infinite scroll, and custom child widget.

carousel_slider A carousel slider widget. Features Infinite scroll Custom child widgets Auto play Supported platforms Flutter Android Flutter iOS Flut

Bart T 1 Nov 25, 2021
A Flutter Widget to make interactive timeline widget.

Bubble Timeline Package A Flutter Widget to make interactive timeline widget. This widget can be used to make Event Timelines, or Timelines for certai

Vansh Goel 12 Sep 22, 2022
Widget, that can make any static located widget hidable

Installing See the official installing guidline from hidable/install Usage & Overview To start using Hidable widget, we have to create a ScrollControl

Anon 18 Dec 16, 2022
A widget that allow user resize the widget with drag

Flutter-Resizable-Widget A widget that allow user resize the widget with drag Note: this widget uses Getx Example bandicam.2021-11-11.12-34-41-056.mp4

MohammadAminZamani.afshar 22 Dec 13, 2022
A widget lib that the widget in this lib can react to flutter ScrollController's offset

Language: English | 中文简体 linked_scroll_widgets A lib full of widgets that can react to the scrollController's offset change,to custom your UI effect.

WenJingRui 8 Oct 16, 2022