settings.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:app_business/service/abase.dart';
  2. import 'package:app_business/service/api.dart';
  3. import 'package:app_business/service/app.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:track_common/service/map_watch.dart';
  6. import 'package:track_common/view.dart';
  7. class SettingsPage extends StatelessWidget {
  8. const SettingsPage({super.key});
  9. ApiService get api => Get.find();
  10. AppService get app => Get.find();
  11. @override
  12. Widget build(BuildContext context) {
  13. return Center(
  14. child: SizedBox(
  15. width: 320,
  16. child: Card(
  17. margin: const EdgeInsets.symmetric(vertical: 24),
  18. child: ListView(
  19. children: [
  20. _SettingsElem(
  21. title: '软件版本', onTap: () {}, tail: Text(app.appVersion)),
  22. _SettingsElem(title: '退出登录', onTap: onSignOut)
  23. ],
  24. ),
  25. )));
  26. }
  27. Widget divider() {
  28. return const Divider(color: Colors.grey);
  29. }
  30. Future<void> onSignOut() async {
  31. final mapWatchService = Get.find<MapWatchService>();
  32. mapWatchService.setMap(null);
  33. api.signOut();
  34. LoginView.to(
  35. canBack: false, thenToPageCall: () => Get.offAllNamed(HomeView.name));
  36. }
  37. }
  38. class _SettingsElem extends StatelessWidget {
  39. const _SettingsElem({required this.onTap, required this.title, this.tail});
  40. final VoidCallback onTap;
  41. final String title;
  42. final Widget? tail;
  43. @override
  44. Widget build(BuildContext context) {
  45. return GestureDetector(
  46. onTap: onTap,
  47. child: Container(
  48. height: 60,
  49. color: Colors.transparent,
  50. padding: const EdgeInsets.symmetric(horizontal: 24),
  51. child: Row(
  52. children: [
  53. Text(title),
  54. const Spacer(),
  55. tail ?? const Icon(Icons.chevron_right)
  56. ],
  57. ),
  58. ));
  59. }
  60. }