Commit 5413611e authored by DatHV's avatar DatHV
Browse files

update screen support - logic

parent e7dd4bc3
import 'package:json_annotation/json_annotation.dart';
// part 'support_item_model.g.dart';
enum SupportItemType { mail, phone, facebook, question, termsOfUse, privacyPolicy }
@JsonSerializable()
class SupportItemModel {
final String icon;
final String title;
final String value;
final SupportItemType type;
SupportItemModel({
required this.icon,
required this.title,
required this.value,
required this.type,
});
factory SupportItemModel.fromJson(Map<String, dynamic> json) {
return SupportItemModel(
icon: json["icon"],
title: json["title"],
value: json["value"],
type: _mapStringToType(json["type"]),
);
}
static SupportItemType _mapStringToType(String type) {
switch (type) {
case "mail":
return SupportItemType.mail;
case "phone":
return SupportItemType.phone;
case "facebook":
return SupportItemType.facebook;
case "question":
return SupportItemType.question;
case "termsOfUse":
return SupportItemType.termsOfUse;
case "privacyPolicy":
return SupportItemType.privacyPolicy;
default:
throw Exception("Loại không hợp lệ: $type");
}
}
}
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/screen/support/support_item_model.dart';
import 'package:mypoint_flutter_app/screen/support/support_screen_viewmodel.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../resouce/base_color.dart';
import '../../widgets/back_button.dart';
import '../pageDetail/campaign_detail_screen.dart';
import '../pageDetail/model/detail_page_rule_type.dart';
class SupportScreen extends StatefulWidget {
const SupportScreen({super.key});
@override
State<SupportScreen> createState() => _SupportScreenState();
}
class _SupportScreenState extends State<SupportScreen> {
final SupportViewModel controller = Get.put(SupportViewModel());
void _handleItemClick(SupportItemType type, String value) async {
switch (type) {
case SupportItemType.mail:
final Uri emailUri = Uri(scheme: 'mailto', path: value);
if (await canLaunchUrl(emailUri)) {
await launchUrl(emailUri);
}
break;
case SupportItemType.phone:
final Uri phoneUri = Uri(scheme: 'tel', path: value);
if (await canLaunchUrl(phoneUri)) {
await launchUrl(phoneUri);
}
break;
case SupportItemType.facebook:
final Uri fbUri = Uri.parse(value);
if (await canLaunchUrl(fbUri)) {
await launchUrl(fbUri);
}
break;
case SupportItemType.question:
Get.to(CampaignDetailScreen(type: DetailPageRuleType.decree));
case SupportItemType.termsOfUse:
Get.to(CampaignDetailScreen(type: DetailPageRuleType.termsOfUse));
case SupportItemType.privacyPolicy:
Get.to(CampaignDetailScreen(type: DetailPageRuleType.privacyPolicy));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: CustomBackButton(),
title: const Text("Hỗ trợ", style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
elevation: 0,
),
body: Obx(() {
if (controller.supportItems.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
return ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
itemCount: controller.supportItems.length,
itemBuilder: (context, index) {
final item = controller.supportItems[index];
return GestureDetector(
onTap: () => _handleItemClick(item.type, item.value),
child: Container(
margin: const EdgeInsets.only(bottom: 10),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 4)],
),
child: Row(
children: [
Icon(_getIcon(item.type), color: BaseColor.primary500, size: 24),
const SizedBox(width: 10),
Expanded(
child: Text(item.title, style: const TextStyle(fontSize: 16)),
),
if (_hasArrow(item.type))
const Icon(Icons.arrow_forward_ios, size: 16, color: Colors.black54),
],
),
),
);
},
);
}),
);
}
/// 🎯 Chuyển đổi `SupportItemType` thành icon phù hợp
IconData _getIcon(SupportItemType type) {
switch (type) {
case SupportItemType.mail:
return Icons.email;
case SupportItemType.phone:
return Icons.phone;
case SupportItemType.facebook:
return Icons.facebook;
case SupportItemType.question:
return Icons.help_outline;
case SupportItemType.termsOfUse:
return Icons.receipt_long;
case SupportItemType.privacyPolicy:
return Icons.lock_outline;
default:
return Icons.info;
}
}
/// 🎯 Xác định có hiển thị mũi tên `>` hay không
bool _hasArrow(SupportItemType type) {
return type == SupportItemType.question ||
type == SupportItemType.termsOfUse ||
type == SupportItemType.privacyPolicy;
}
}
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/screen/support/support_item_model.dart';
class SupportViewModel extends GetxController {
var supportItems = <SupportItemModel>[].obs;
@override
void onInit() {
super.onInit();
loadSupportData();
}
Future<void> loadSupportData() async {
try {
final String response = await rootBundle.loadString('assets/data/support_data.json');
final Map<String, dynamic> data = json.decode(response);
final List<dynamic> items = data["data"]["items"];
supportItems.value = items.map((item) => SupportItemModel.fromJson(item)).toList();
} catch (e) {
print("Lỗi load dữ liệu: $e");
}
}
}
......@@ -21,8 +21,8 @@ class CustomBackButton extends StatelessWidget {
height: 36,
width: 36,
decoration: BoxDecoration(
border: Border.all(color: BaseColor.second400, width: 1),
borderRadius: BorderRadius.circular(6),
border: Border.all(color: BaseColor.second300, width: 1),
borderRadius: BorderRadius.circular(8),
color: Colors.white,
),
),
......
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../resouce/base_color.dart';
import '../screen/support/support_screen.dart';
class SupportButton extends StatelessWidget {
const SupportButton({super.key});
......@@ -36,12 +37,3 @@ class SupportButton extends StatelessWidget {
);
}
}
class SupportScreen extends StatelessWidget {
const SupportScreen({super.key});
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
......@@ -77,6 +77,7 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/data/
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment