wearos: ambient support
This commit is contained in:
parent
b3ceb4d5de
commit
97462997a8
@ -3,6 +3,8 @@ import 'dart:async';
|
|||||||
import 'package:firka/helpers/api/model/timetable.dart';
|
import 'package:firka/helpers/api/model/timetable.dart';
|
||||||
import 'package:firka/wear_main.dart';
|
import 'package:firka/wear_main.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
|
import 'package:wear_plus/wear_plus.dart';
|
||||||
|
|
||||||
import '../../../ui/colors.dart';
|
import '../../../ui/colors.dart';
|
||||||
import '../../../ui/widgets/circular_progress_indicator.dart';
|
import '../../../ui/widgets/circular_progress_indicator.dart';
|
||||||
@ -24,6 +26,7 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
|||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
bool init = false;
|
bool init = false;
|
||||||
|
WearMode mode = WearMode.active;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -58,7 +61,9 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> buildBody(BuildContext context) {
|
List<Widget> buildBody(BuildContext context, WearMode mode) {
|
||||||
|
WakelockPlus.enable();
|
||||||
|
|
||||||
var body = List<Widget>.empty(growable: true);
|
var body = List<Widget>.empty(growable: true);
|
||||||
if (!init) {
|
if (!init) {
|
||||||
return body;
|
return body;
|
||||||
@ -148,8 +153,11 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
|||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${currentBreakProgress.inMinutes} "
|
currentBreakProgress.inMinutes < 1
|
||||||
"min${currentBreakProgress.inMinutes == 1 ? '' : 's'} left",
|
? "less than a minute left"
|
||||||
|
: "${currentBreakProgress.inMinutes} "
|
||||||
|
"min${currentBreakProgress.inMinutes == 1 ? '' : 's'} "
|
||||||
|
"left",
|
||||||
style: TextStyle(color: defaultColors.secondaryText, fontSize: 16),
|
style: TextStyle(color: defaultColors.secondaryText, fontSize: 16),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -184,7 +192,9 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
|||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${timeLeft.inMinutes} "
|
timeLeft.inMinutes < 1
|
||||||
|
? "less than a minute left"
|
||||||
|
: "${timeLeft.inMinutes} "
|
||||||
"min${timeLeft.inMinutes == 1 ? '' : 's'} left",
|
"min${timeLeft.inMinutes == 1 ? '' : 's'} left",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: defaultColors.secondaryText, fontSize: 16),
|
color: defaultColors.secondaryText, fontSize: 16),
|
||||||
@ -203,13 +213,46 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var body = buildBody(context);
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: defaultColors.ambientBackgroundColor,
|
backgroundColor: mode == WearMode.active
|
||||||
|
? defaultColors.activeBackgroundColor
|
||||||
|
: defaultColors.ambientBackgroundColor,
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
||||||
children: body,
|
WatchShape(builder: (context, shape, child) {
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
child!,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: AmbientMode(
|
||||||
|
builder: (context, mode, child) {
|
||||||
|
if (this.mode != mode) {
|
||||||
|
Timer(Duration(milliseconds: 100), () {
|
||||||
|
setState(() {
|
||||||
|
this.mode = mode;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
// children: buildBody(context, mode),
|
||||||
|
children: <Widget>[
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.only(top: 75),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: buildBody(context, mode),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import 'package:firka/wear_main.dart';
|
import 'package:firka/wear_main.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
|
|
||||||
class WearLoginScreen extends StatelessWidget {
|
class WearLoginScreen extends StatelessWidget {
|
||||||
final WearAppInitialization data;
|
final WearAppInitialization data;
|
||||||
@ -9,6 +10,7 @@ class WearLoginScreen extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
WakelockPlus.disable();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Stub'),
|
title: const Text('Stub'),
|
||||||
|
@ -2,7 +2,7 @@ import 'dart:ui';
|
|||||||
|
|
||||||
class WearColors {
|
class WearColors {
|
||||||
|
|
||||||
Color backgroundColor;
|
Color activeBackgroundColor;
|
||||||
Color ambientBackgroundColor;
|
Color ambientBackgroundColor;
|
||||||
Color radiusColor;
|
Color radiusColor;
|
||||||
Color primaryText;
|
Color primaryText;
|
||||||
@ -10,7 +10,7 @@ class WearColors {
|
|||||||
Color tertiaryText;
|
Color tertiaryText;
|
||||||
|
|
||||||
WearColors({
|
WearColors({
|
||||||
required this.backgroundColor,
|
required this.activeBackgroundColor,
|
||||||
required this.ambientBackgroundColor,
|
required this.ambientBackgroundColor,
|
||||||
required this.radiusColor,
|
required this.radiusColor,
|
||||||
required this.primaryText,
|
required this.primaryText,
|
||||||
@ -21,7 +21,7 @@ class WearColors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WearColors defaultColors = WearColors(
|
WearColors defaultColors = WearColors(
|
||||||
backgroundColor: Color(0xff0c1201),
|
activeBackgroundColor: Color(0xff0c1201),
|
||||||
ambientBackgroundColor: Color(0xff000000),
|
ambientBackgroundColor: Color(0xff000000),
|
||||||
radiusColor: Color(0xffa6dc22),
|
radiusColor: Color(0xffa6dc22),
|
||||||
primaryText: Color(0xffcbee71),
|
primaryText: Color(0xffcbee71),
|
||||||
|
@ -9,7 +9,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
|
||||||
import 'package:wear_plus/wear_plus.dart';
|
import 'package:wear_plus/wear_plus.dart';
|
||||||
|
|
||||||
import 'helpers/api/client/kreta_client.dart';
|
import 'helpers/api/client/kreta_client.dart';
|
||||||
@ -60,8 +59,6 @@ Future<WearAppInitialization> initializeApp() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wearMain(MethodChannel platform) async {
|
void wearMain(MethodChannel platform) async {
|
||||||
WakelockPlus.disable();
|
|
||||||
|
|
||||||
// TODO: fix the error handling currently not pushing to the error page
|
// TODO: fix the error handling currently not pushing to the error page
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user