0% found this document useful (0 votes)
0 views9 pages

MB amaliy 3

The document outlines a project for developing a mobile calculator application that performs basic arithmetic operations using Flutter and Dart. It details the application's design, key components, button functionalities, and error handling mechanisms. The project aims to provide a user-friendly interface for real-time calculations with a minimalistic design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views9 pages

MB amaliy 3

The document outlines a project for developing a mobile calculator application that performs basic arithmetic operations using Flutter and Dart. It details the application's design, key components, button functionalities, and error handling mechanisms. The project aims to provide a user-friendly interface for real-time calculations with a minimalistic design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

O’ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALARI

VAZIRLIGI
QARSHI DAVLAT TEXNIKA UNVERSTETI

“Raqamli texnologiyalar va sun'iy intellekt” fakulteti


DI-607-22 guruh talabasining
“Mobil ilovalarni ishlab chiqish”
FANIDAN

3-AMALIY ISH
BAJARDI: Nurmatov B.
QABUL QILDI: Yaxyayev S.

QARSHI 2025
Mavzu:Kalkulyator Dasturining Nazariy Qismi

Loyihaning maqsadi

Ushbu loyiha oddiy arifmetik amallarni (qo‘shish, ayirish, ko‘paytirish, bo‘lish)


bajaruvchi mobil kalkulyator yaratishdan iborat. Foydalanuvchi qulay interfeys
orqali raqam va amallarni tanlaydi hamda natijani real vaqt rejimida ko‘radi.

Ishlatilgan texnologiyalar

Flutter: Mobil ilovani yaratish uchun asosiy freymvork.

Dart: Ilovaning dasturlash tili.

math_expressions: Matematika ifodalarini (masalan, 5+2*3) avtomatik tahlil


qilish va hisoblash uchun paket.

Ilovaning asosiy komponentlari

MaterialApp: Ilovaning asosiy tuzilmasini ta'minlaydi.

Scaffold: Ekran tuzilmasini (AppBar, Body) yaratadi.

StatefulWidget: Foydalanuvchi bilan interaktiv ishlash uchun holat saqlovchi


vidjet.

GridView: Kalkulyator tugmalarini matritsa shaklida joylashtirish uchun.

Tugmalar funksiyasi

Ilovada quyidagi tugmalar mavjud:

Tugma Vazifasi

C Ekranni tozalaydi

⌫ Bir belgini o‘chiradi

= Natijani hisoblaydi

+-×÷ Arifmetik amallar

0-9, 00, . Raqam va nuqta kiritish

Hisoblash mexanizmi
Ifodani hisoblash:

Foydalanuvchi kiritgan ifoda matn (String) ko‘rinishida saqlanadi.

× va ÷ belgilar * va / ga almashtiriladi.

math_expressions kutubxonasi yordamida:

Parser yordamida ifoda tahlil qilinadi.

ContextModel orqali ifoda hisoblanadi.

Natija foydalanuvchiga ko‘rsatiladi.

Kutilmagan xatoliklar:

try-catch bloki orqali noto‘g‘ri ifodalarda Xato! deb chiqadi (masalan, 8+÷5).

Dizayn va UI

Qora fon: ko‘zni charchatmaydigan minimalistik ko‘rinish.

Tugmalar ranglari:

Asosiy amal tugmalari (orange)

Tozalash tugmalari (red)

Oddiy raqam tugmalari (dark gray)

GridView: barcha tugmalarni 4x5 panjarada ko‘rsatadi.

Dastur kodi:

import 'package:flutter/material.dart';

import 'package:math_expressions/math_expressions.dart';

void main() {

runApp(CalculatorApp());

}
class CalculatorApp extends StatelessWidget {

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Kalkulyator',

theme: ThemeData.dark().copyWith(

scaffoldBackgroundColor: Color(0xFF1E1E1E),

),

home: CalculatorHomePage(),

debugShowCheckedModeBanner: false,

);

class CalculatorHomePage extends StatefulWidget {

@override

_CalculatorHomePageState createState() =>


_CalculatorHomePageState();

class _CalculatorHomePageState extends State<CalculatorHomePage> {

String input = '';

String result = '0';

void buttonPressed(String value) {

setState(() {

if (value == 'C') {
input = '';

result = '0';

} else if (value == '⌫') {

if (input.isNotEmpty) input = input.substring(0, input.length - 1);

} else if (value == '=') {

try {

result = _calculate(input);

} catch (e) {

result = 'Xato!';

} else {

input += value;

});

String _calculate(String expression) {

try {

expression = expression.replaceAll('×', '*').replaceAll('÷', '/');

Parser p = Parser();

Expression exp = p.parse(expression);

ContextModel cm = ContextModel();

double eval = exp.evaluate(EvaluationType.REAL, cm);

return eval.toString();
} catch (_) {

return 'Xato!';

final List<String> buttons = [

'C', '⌫', '%', '÷',

'7', '8', '9', '×',

'4', '5', '6', '-',

'1', '2', '3', '+',

'00', '0', '.', '=',

];

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text('Kalkulyator'),

centerTitle: true,

backgroundColor: Colors.black,

),

body: Column(

children: [

Expanded(

child: Container(
padding: EdgeInsets.all(20),

alignment: Alignment.bottomRight,

child: Column(

mainAxisAlignment: MainAxisAlignment.end,

children: [

Text(

input,

style: TextStyle(fontSize: 24, color: Colors.white54),

),

SizedBox(height: 10),

Text(

result,

style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold),

),

],

),

),

),

Divider(color: Colors.white30),

Expanded(

flex: 2,

child: GridView.builder(

itemCount: buttons.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(

crossAxisCount: 4, childAspectRatio: 1.2),

itemBuilder: (context, index) {

final btn = buttons[index];

return Padding(

padding: EdgeInsets.all(8),

child: ElevatedButton(

onPressed: () => buttonPressed(btn),

style: ElevatedButton.styleFrom(

backgroundColor: _getButtonColor(btn),

shape: RoundedRectangleBorder(

borderRadius: BorderRadius.circular(16)),

),

child: Text(

btn,

style: TextStyle(fontSize: 24, color: Colors.white),

),

),

);

},

),

),

],
),

);

Color _getButtonColor(String value) {

if (value == 'C' || value == '⌫') return Colors.redAccent;

if (value == '=' || value == '+' || value == '-' || value == '×' || value == '÷')

return Colors.orange;

return Colors.grey[850]!;

You might also like