first commit

This commit is contained in:
2026-02-07 15:57:09 +07:00
commit 157096f164
1153 changed files with 415766 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
class CurrencyModel {
CurrencyModel({
this.id,
this.name,
this.countryName,
this.code,
this.symbol,
this.position,
this.status,
this.isDefault,
this.createdAt,
this.updatedAt,
});
CurrencyModel.fromJson(dynamic json) {
id = json['id'];
name = json['name'];
countryName = json['country_name'];
code = json['code'];
symbol = json['symbol'];
position = json['position'];
status = json['status'];
isDefault = json['is_default'];
createdAt = json['created_at'];
updatedAt = json['updated_at'];
}
num? id;
String? name;
dynamic countryName;
String? code;
String? symbol;
dynamic position;
bool? status;
bool? isDefault;
String? createdAt;
String? updatedAt;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = id;
map['name'] = name;
map['country_name'] = countryName;
map['code'] = code;
map['symbol'] = symbol;
map['position'] = position;
map['status'] = status;
map['is_default'] = isDefault;
map['created_at'] = createdAt;
map['updated_at'] = updatedAt;
return map;
}
}

View File

@@ -0,0 +1,7 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../Model/currency_model.dart';
import '../Repo/currency_repo.dart';
CurrencyRepo repo = CurrencyRepo();
final currencyProvider = FutureProvider.autoDispose<List<CurrencyModel>>((ref) => repo.fetchAllCurrency());

View File

@@ -0,0 +1,63 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../../../Const/api_config.dart';
import '../../../Repository/constant_functions.dart';
import '../../../http_client/customer_http_client_get.dart';
import '../Model/currency_model.dart';
class CurrencyRepo {
Future<List<CurrencyModel>> fetchAllCurrency() async {
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
final uri = Uri.parse('${APIConfig.url}/currencies');
final response = await clientGet.get(url: uri);
if (response.statusCode == 200) {
final parsedData = jsonDecode(response.body) as Map<String, dynamic>;
final partyList = parsedData['data'] as List<dynamic>;
// Filter and map the list
return partyList
.where((category) => category['status'] == true) // Filter by status
.map((category) => CurrencyModel.fromJson(category))
.toList();
} else {
throw Exception('Failed to fetch Currency');
}
}
// Future<List<CurrencyModel>> fetchAllCurrency() async {
// final uri = Uri.parse('${APIConfig.url}/currencies');
//
// final response = await http.get(uri, headers: {
// 'Accept': 'application/json',
// 'Authorization': await getAuthToken(),
// });
//
// if (response.statusCode == 200) {
// final parsedData = jsonDecode(response.body) as Map<String, dynamic>;
//
// final partyList = parsedData['data'] as List<dynamic>;
// return partyList.map((category) => CurrencyModel.fromJson(category)).toList();
// // Parse into Party objects
// } else {
// throw Exception('Failed to fetch Currency');
// }
// }
Future<bool> setDefaultCurrency({required num id}) async {
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
final uri = Uri.parse('${APIConfig.url}/currencies/$id');
final response = await clientGet.get(url: uri);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,129 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mobile_pos/Screens/Currency/Provider/currency_provider.dart';
import 'package:mobile_pos/generated/l10n.dart' as lang;
import '../../GlobalComponents/glonal_popup.dart';
import '../../constant.dart';
import '../../currency.dart';
import 'Model/currency_model.dart';
import 'Repo/currency_repo.dart';
class CurrencyScreen extends StatefulWidget {
const CurrencyScreen({super.key});
@override
State<CurrencyScreen> createState() => _CurrencyScreenState();
}
class _CurrencyScreenState extends State<CurrencyScreen> {
CurrencyModel selectedCurrency = CurrencyModel(name: currencyName, symbol: currency);
@override
Widget build(BuildContext context) {
return Consumer(builder: (context, ref, __) {
final currencyData = ref.watch(currencyProvider);
return GlobalPopup(
child: Scaffold(
backgroundColor: kWhite,
resizeToAvoidBottomInset: true,
appBar: AppBar(
backgroundColor: Colors.white,
title: Text(
lang.S.of(context).currency,
//'Currency',
),
centerTitle: true,
iconTheme: const IconThemeData(color: Colors.black),
elevation: 0.0,
),
body: currencyData.when(
data: (currencyList) {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: currencyList.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(bottom: 15),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: selectedCurrency.name == currencyList[index].name ? kMainColor : kWhite,
boxShadow: [
BoxShadow(color: const Color(0xff0C1A4B).withValues(alpha: 0.24), blurRadius: 1),
BoxShadow(color: const Color(0xff473232).withValues(alpha: 0.05), offset: const Offset(0, 3), spreadRadius: -1, blurRadius: 8)
],
),
child: ListTile(
selected: selectedCurrency.name == currencyList[index].name,
selectedColor: Colors.white,
onTap: () {
setState(() {
selectedCurrency = currencyList[index];
});
},
title: Text('${currencyList[index].name} - ${currencyList[index].symbol}'),
trailing: const Icon(
(Icons.arrow_forward_ios),
),
),
),
);
},
),
),
);
},
error: (error, stackTrace) {
return null;
},
loading: () => const Center(child: CircularProgressIndicator()),
),
bottomNavigationBar: Padding(
padding: const EdgeInsets.all(10.0),
child: GestureDetector(
onTap: () async {
try {
EasyLoading.show();
final isSet = await CurrencyRepo().setDefaultCurrency(id: selectedCurrency.id!);
if (isSet) {
await CurrencyMethods().saveCurrencyDataInLocalDatabase(
selectedCurrencyName: selectedCurrency.name,
selectedCurrencySymbol: selectedCurrency.symbol,
);
Navigator.pop(context);
} else {
EasyLoading.showError('Something went wrong');
}
} catch (e) {
EasyLoading.showError('An error occurred: $e');
} finally {
EasyLoading.dismiss();
}
},
child: Container(
height: 50,
decoration: const BoxDecoration(
color: kMainColor,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
lang.S.of(context).save,
style: const TextStyle(fontSize: 18, color: Colors.white),
),
),
),
),
),
),
);
});
}
}