mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Added clock & battery widgets in reader.
This commit is contained in:
@@ -131,10 +131,11 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
child: widget.child,
|
||||
),
|
||||
buildPageInfoText(),
|
||||
buildStatusInfo(),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
right: 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 36,
|
||||
child: buildEpChangeButton(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
@@ -424,6 +425,20 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildStatusInfo() {
|
||||
return Positioned(
|
||||
bottom: 13,
|
||||
right: 25,
|
||||
child: Row(
|
||||
children: [
|
||||
_ClockWidget(),
|
||||
const SizedBox(width: 10),
|
||||
_BatteryWidget(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void openChapterDrawer() {
|
||||
showSideBar(
|
||||
context,
|
||||
@@ -569,6 +584,190 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
}
|
||||
|
||||
class _BatteryWidget extends StatefulWidget {
|
||||
@override
|
||||
_BatteryWidgetState createState() => _BatteryWidgetState();
|
||||
}
|
||||
|
||||
class _BatteryWidgetState extends State<_BatteryWidget> {
|
||||
late Battery _battery;
|
||||
late int _batteryLevel;
|
||||
Timer? _timer;
|
||||
bool _hasBattery = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_battery = Battery();
|
||||
_checkBatteryAvailability();
|
||||
if(_hasBattery) {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
final batteryLevel = await _battery.batteryLevel;
|
||||
if(_batteryLevel != batteryLevel) {
|
||||
setState(() {
|
||||
_batteryLevel = batteryLevel;
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
void _checkBatteryAvailability() async {
|
||||
try {
|
||||
_batteryLevel = await _battery.batteryLevel;
|
||||
if (_batteryLevel != -1) {
|
||||
setState(() {
|
||||
_hasBattery = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_hasBattery = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_hasBattery = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_hasBattery) {
|
||||
return const SizedBox.shrink(); //Empty Widget
|
||||
}
|
||||
|
||||
return _batteryInfo(_batteryLevel);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _batteryInfo(int batteryLevel) {
|
||||
IconData batteryIcon;
|
||||
Color batteryColor = Colors.black;
|
||||
|
||||
if (batteryLevel >= 96) {
|
||||
batteryIcon = Icons.battery_full_sharp;
|
||||
} else if (batteryLevel >= 84) {
|
||||
batteryIcon = Icons.battery_6_bar_sharp;
|
||||
} else if (batteryLevel >= 72) {
|
||||
batteryIcon = Icons.battery_5_bar_sharp;
|
||||
} else if (batteryLevel >= 60) {
|
||||
batteryIcon = Icons.battery_4_bar_sharp;
|
||||
} else if (batteryLevel >= 48) {
|
||||
batteryIcon = Icons.battery_3_bar_sharp;
|
||||
} else if (batteryLevel >= 36) {
|
||||
batteryIcon = Icons.battery_2_bar_sharp;
|
||||
} else if (batteryLevel >= 24) {
|
||||
batteryIcon = Icons.battery_1_bar_sharp;
|
||||
} else if (batteryLevel >= 12) {
|
||||
batteryIcon = Icons.battery_0_bar_sharp;
|
||||
} else {
|
||||
batteryIcon = Icons.battery_alert_sharp;
|
||||
batteryColor = Colors.red;
|
||||
}
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
batteryIcon,
|
||||
size: 16,
|
||||
color: batteryColor,
|
||||
// Stroke
|
||||
shadows: List.generate(9,
|
||||
(index) {
|
||||
if(index == 4) {
|
||||
return null;
|
||||
}
|
||||
double offsetX = (index % 3 - 1) * 0.8;
|
||||
double offsetY = ((index / 3).floor() - 1) * 0.8;
|
||||
return Shadow(
|
||||
color: context.colorScheme.onInverseSurface,
|
||||
offset: Offset(offsetX, offsetY),
|
||||
);
|
||||
},
|
||||
).whereType<Shadow>().toList(),
|
||||
),
|
||||
Stack(
|
||||
children: [
|
||||
Text(
|
||||
'$batteryLevel%',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
foreground: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.4
|
||||
..color = context.colorScheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
Text('$batteryLevel%'),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ClockWidget extends StatefulWidget {
|
||||
@override
|
||||
_ClockWidgetState createState() => _ClockWidgetState();
|
||||
}
|
||||
|
||||
class _ClockWidgetState extends State<_ClockWidget> {
|
||||
late String _currentTime;
|
||||
late Timer _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentTime = _getCurrentTime();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
final time = _getCurrentTime();
|
||||
if(_currentTime != time) {
|
||||
setState(() {
|
||||
_currentTime = time;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _getCurrentTime() {
|
||||
final now = DateTime.now();
|
||||
return "${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
Text(
|
||||
_currentTime,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
foreground: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.4
|
||||
..color = context.colorScheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
Text(_currentTime),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChaptersView extends StatefulWidget {
|
||||
const _ChaptersView(this.reader);
|
||||
|
||||
|
Reference in New Issue
Block a user