Fix GPS信号表示・制御
This commit is contained in:
78
lib/widgets/gps_status.dart
Normal file
78
lib/widgets/gps_status.dart
Normal file
@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/widgets/GameState/Colors.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
//import 'package:rogapp/widgets/custom_icons.dart';
|
||||
|
||||
enum GPSStatus { high, middle, low }
|
||||
|
||||
class GpsSignalStrengthIndicator extends StatelessWidget {
|
||||
final DestinationController destinationController; // = Get.find<DestinationController>();
|
||||
final bool minimized;
|
||||
|
||||
// コンストラクタにminimizedパラメータを追加し、デフォルト値をfalseに設定
|
||||
const GpsSignalStrengthIndicator({
|
||||
Key? key,
|
||||
required this.destinationController,
|
||||
this.minimized = false, // ここでデフォルト値を指定
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
final signalStrength = destinationController.getGpsSignalStrength();
|
||||
IconData iconData;
|
||||
Color backgroundColor;
|
||||
String text;
|
||||
|
||||
// signalStrengthに応じて、アイコン、背景色、テキストを設定
|
||||
switch (signalStrength) {
|
||||
case 'high':
|
||||
backgroundColor = Colors.green;
|
||||
iconData = Icons.signal_cellular_alt;
|
||||
//iconData = CustomIcons.gps_signal_high_0;
|
||||
text = 'GPS 強';
|
||||
break;
|
||||
case 'medium':
|
||||
backgroundColor = Colors.orange;
|
||||
iconData = Icons.signal_cellular_alt_2_bar;
|
||||
//iconData = CustomIcons.gps_signal_middle_0;
|
||||
text = 'GPS 中';
|
||||
break;
|
||||
default:
|
||||
backgroundColor = Colors.grey; // Fallback color
|
||||
iconData = Icons.signal_cellular_connected_no_internet_4_bar;
|
||||
//iconData = CustomIcons.gps_signal_low_0;
|
||||
text = 'GPS 弱';
|
||||
}
|
||||
|
||||
// コンテナの設定をminimizedの値に応じて調整
|
||||
return Container(
|
||||
height: minimized ? 40 : null,
|
||||
width: minimized ? 40 : null,
|
||||
padding: minimized ? null : const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
shape: minimized ? BoxShape.circle : BoxShape.rectangle,
|
||||
borderRadius: minimized ? null : BorderRadius.circular(10),
|
||||
),
|
||||
child: minimized
|
||||
? Center(
|
||||
child: Icon(iconData, color: Colors.white, size: 24),
|
||||
)
|
||||
: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(iconData, color: Colors.white),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user