134 lines
3.9 KiB
Dart
134 lines
3.9 KiB
Dart
import 'dart:async';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:percent_indicator/linear_percent_indicator.dart';
|
|
import 'package:rainbow_color/rainbow_color.dart';
|
|
|
|
|
|
class AppBarCommonNav extends StatefulWidget implements PreferredSizeWidget {
|
|
|
|
@override
|
|
_AppBarCommonNav createState() => _AppBarCommonNav();
|
|
|
|
@override
|
|
Size get preferredSize => const Size.fromHeight(60);
|
|
}
|
|
|
|
class _AppBarCommonNav extends State<AppBarCommonNav> with SingleTickerProviderStateMixin {
|
|
Animation<Color> colorAnim;
|
|
AnimationController colorController;
|
|
|
|
@override
|
|
void initState() {
|
|
|
|
colorController =
|
|
AnimationController(duration: Duration(seconds: 4), vsync: this);
|
|
|
|
colorAnim = RainbowColorTween([Colors.white70,
|
|
Colors.blueGrey,
|
|
Colors.blueAccent,
|
|
Colors.lightBlue,
|
|
Colors.lightBlueAccent,
|
|
Colors.yellowAccent,
|
|
Colors.orange,
|
|
Colors.orangeAccent,
|
|
Colors.yellowAccent,
|
|
Color(0xffcce6ff)])
|
|
.animate(colorController)
|
|
..addListener(() { setState(() {}); })
|
|
..addStatusListener((status) {
|
|
if (status == AnimationStatus.completed) {
|
|
Timer(Duration(seconds: 10), () {
|
|
//colorController.reset();
|
|
if ( mounted ) {
|
|
colorController.forward();
|
|
}
|
|
});
|
|
} else if (status == AnimationStatus.dismissed) {
|
|
colorController.forward();
|
|
}
|
|
});
|
|
colorController.forward();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppBar(
|
|
backgroundColor: Colors.black,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
|
|
getAnimatedWidget(),
|
|
Image.asset(
|
|
'asset/image/WT_long_logo.png',
|
|
fit: BoxFit.cover,
|
|
height: 65.0,
|
|
),
|
|
],
|
|
),
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () =>
|
|
{
|
|
Navigator.of(context).pop()
|
|
},
|
|
)
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
//sizeController.dispose();
|
|
colorController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Widget getAnimatedWidget() {
|
|
double percent = Cache().getPercentExercises();
|
|
if ( percent == -1) {
|
|
ExerciseRepository exerciseRepository = ExerciseRepository();
|
|
exerciseRepository.getBaseExerciseFinishedPercent();
|
|
percent = Cache().getPercentExercises();
|
|
}
|
|
int sizeExerciseList = Cache().getExercises() == null? 0 : Cache().getExercises().length;
|
|
if ( sizeExerciseList == 0 ) {
|
|
return Stack(
|
|
alignment: Alignment.topLeft,
|
|
children: [
|
|
Text(AppLocalizations.of(context).translate("Make your first test"),
|
|
style: TextStyle(fontSize: 16, color: colorAnim.value, shadows: [Shadow(color: Colors.purple , blurRadius: 15)]),
|
|
|
|
),
|
|
//TestProgress(animation: sizeAnim),
|
|
]
|
|
);
|
|
} else {
|
|
|
|
return Stack(
|
|
alignment: Alignment.topLeft,
|
|
children: [
|
|
LinearPercentIndicator(
|
|
width: 120.0,
|
|
lineHeight: 14.0,
|
|
percent: percent,
|
|
center: Text(
|
|
(percent * 100).toStringAsFixed(0) + "% finished",
|
|
style: new TextStyle(fontSize: 12.0),
|
|
),
|
|
trailing: Icon(percent > 0.6 ? Icons.mood : Icons.mood_bad, color: colorAnim.value,),
|
|
linearStrokeCap: LinearStrokeCap.roundAll,
|
|
backgroundColor: colorAnim.value,
|
|
progressColor: Color(0xff73e600),
|
|
animation: true,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|