103 lines
3.6 KiB
Dart
103 lines
3.6 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
|
|
|
import '../theme/themes.dart';
|
|
import 'horizontal_progress.dart';
|
|
|
|
class UserStatistics extends StatelessWidget {
|
|
final UserDataDto? userDataDto;
|
|
|
|
UserStatistics(this.userDataDto);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final words = userDataDto?.allWordsStatistics?.words ?? [];
|
|
words.sort(
|
|
(p, n) => (n.correct / n.total).compareTo(p.correct / p.total),
|
|
);
|
|
final learnedWords = words
|
|
.where((w) => w.correct > 10 && w.correct / w.total > 0.9)
|
|
.map((e) => e.word)
|
|
.toSet();
|
|
final learnedWordsLength = learnedWords.length;
|
|
final lastDigit = learnedWordsLength % 10;
|
|
final String? totalWordsText;
|
|
if (learnedWordsLength == 0) {
|
|
totalWordsText = null;
|
|
} else if (lastDigit == 0 || lastDigit >= 5) {
|
|
totalWordsText = 'Ты уже знаешь $learnedWordsLength слов!';
|
|
} else if (lastDigit == 1) {
|
|
totalWordsText = 'Ты уже знаешь $learnedWordsLength слово!';
|
|
} else {
|
|
totalWordsText = 'Ты уже знаешь $learnedWordsLength слова!';
|
|
}
|
|
|
|
return Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 8.0),
|
|
child: Row(
|
|
children: [
|
|
if (totalWordsText != null)
|
|
Text(
|
|
totalWordsText,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
height: 200.h,
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: borderGray),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
padding: EdgeInsets.symmetric(horizontal: 8.0.w),
|
|
child: words.isEmpty
|
|
? Center(
|
|
child: AutoSizeText('Тут будут все пройденные слова'),
|
|
)
|
|
: ListView.builder(
|
|
itemCount: words.length,
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) {
|
|
final word = words[index];
|
|
return Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 2.0.h),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'${word.word}',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
Flexible(
|
|
child: SizedBox(
|
|
width: MediaQuery.of(context).size.width / 2.5,
|
|
child: HorizontalProgressWidget(
|
|
(word.correct * 100).floor(),
|
|
(word.total * 100).floor(),
|
|
learnedWords.contains(word.word) ? golden : progressBlue,
|
|
borderColor: borderGray,
|
|
height: 20.h,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|