-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
228 lines (208 loc) · 6.7 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
runApp(const DebtManagerApp());
}
class DebtManagerApp extends StatelessWidget {
const DebtManagerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Qarz Manager',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const DebtManagerHomePage(),
);
}
}
class DebtItem {
String name;
double amount;
bool isOwedByUser;
DebtItem({
required this.name,
required this.amount,
required this.isOwedByUser,
});
}
class DebtManagerHomePage extends StatefulWidget {
const DebtManagerHomePage({super.key});
@override
_DebtManagerHomePageState createState() => _DebtManagerHomePageState();
}
class _DebtManagerHomePageState extends State<DebtManagerHomePage> {
final TextEditingController _nameController = TextEditingController();
final TextEditingController _amountController = TextEditingController();
List<DebtItem> _debtsList = [];
bool _isOwedByUser = false;
@override
void initState() {
super.initState();
_loadSavedData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Qarz Manager'),
),
body: Stack(
// Wrap with Stack
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
controller: _nameController,
decoration: const InputDecoration(labelText: 'Naam'),
),
const SizedBox(height: 12.0),
TextField(
controller: _amountController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(labelText: 'Raqam (Rs.)'),
),
const SizedBox(height: 12.0),
Row(
children: [
const Text('Meine dene hein? '),
Checkbox(
value: _isOwedByUser,
onChanged: (value) {
setState(() {
_isOwedByUser = value!;
});
},
),
],
),
const SizedBox(height: 12.0),
ElevatedButton(
onPressed: _addDebt,
child: const Text('Dakhla'),
),
const SizedBox(height: 24.0),
Text(
'Qarzay:',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline, // Add this line
),
),
Expanded(
child: ReorderableListView(
onReorder: (oldIndex, newIndex) {
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final item = _debtsList.removeAt(oldIndex);
_debtsList.insert(newIndex, item);
});
},
children: _debtsList
.map((debt) => ListTile(
key: Key(debt.name),
title: Text(
'${debt.name}: Rs. ${debt.amount.toInt()} ${debt.isOwedByUser ? "\n(Meine dene hein)" : "\n(Meine lene hein)"}'),
trailing: IconButton(
icon: const Icon(Icons.delete),
onPressed: () => _deleteDebt(debt),
),
))
.toList(),
),
),
],
),
),
Positioned(
left: 0,
right: 0,
bottom: 0,
child: GestureDetector(
onTap: _launchURL,
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(vertical: 16.0),
color: const Color.fromARGB(255, 255, 255, 255),
child: const Text(
'Made by Shujaat',
style: TextStyle(
fontSize: 14.0,
color: Color.fromARGB(255, 0, 0, 0),
),
),
),
),
),
],
),
);
}
void _addDebt() {
final name = _nameController.text;
final amountStr = _amountController.text;
if (name.isEmpty || amountStr.isEmpty) {
return;
}
final amount = double.tryParse(amountStr);
if (amount == null || amount <= 0) {
return;
}
setState(() {
_debtsList.add(DebtItem(
name: name,
amount: amount,
isOwedByUser: _isOwedByUser,
));
});
_nameController.clear();
_amountController.clear();
_saveData();
}
void _deleteDebt(DebtItem debt) {
setState(() {
_debtsList.remove(debt);
});
_saveData();
}
void _saveData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> debtsStringList = _debtsList
.map((debt) =>
"${debt.name},${debt.amount.toString()},${debt.isOwedByUser.toString()}")
.toList();
prefs.setStringList('debtsList', debtsStringList);
}
void _loadSavedData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String>? debtsStringList = prefs.getStringList('debtsList');
if (debtsStringList != null) {
setState(() {
_debtsList = debtsStringList.map((debtString) {
List<String> values = debtString.split(',');
return DebtItem(
name: values[0],
amount: double.parse(values[1]),
isOwedByUser: values[2] == 'true',
);
}).toList();
});
}
}
}
void _launchURL() async {
const url =
'https://www.instagram.com/malik._.shujaat?igshid=emR0eGQ1OGdocG04';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}