Skip to content

Instantly share code, notes, and snippets.

@yousefmasry4
Created September 20, 2022 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yousefmasry4/7c594f6c778058a7c841046f69bff404 to your computer and use it in GitHub Desktop.
Save yousefmasry4/7c594f6c778058a7c841046f69bff404 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Calculator'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _answer = 0;
List<int> list = [];
void _mem(int x) {
setState(() {
_answer = x;
if (list.length == 2) {
list[0] = list[1];
list[1] = x;
} else {
list.add(x);
}
});
}
void _sum() {
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${_answer}"),
FloatingActionButton(
onPressed: ()=>_mem(1),
tooltip: 'Increment',
child: const Text("1"),
),
FloatingActionButton(
onPressed: ()=>_mem(2),
tooltip: 'Increment',
child: const Text("2"),
),
FloatingActionButton(
onPressed: () {
setState((){
if(list.length == 2)
_answer= list[0]+list[1];
});
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment