settings.dart 1.6 KB

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