Skip to content

Commit f0e8a75

Browse files
Merge branch 'main' into dev
2 parents ad6914c + 05823f7 commit f0e8a75

File tree

1 file changed

+79
-9
lines changed

1 file changed

+79
-9
lines changed

lib/sub_pages_builder/learning_pages/learning_pages_build.dart

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,71 @@ class _WordCardOverViewPage extends State<WordCardOverViewPage> {
580580
ScrollController classController = ScrollController();
581581
bool allowJsonScorll = true;
582582
bool allowClassScorll = false;
583+
int forceColumn = 0;
583584

584585
@override
585586
Widget build(BuildContext context) {
586587
MediaQueryData mediaQuery = MediaQuery.of(context);
587588
return Scaffold(
588589
appBar: AppBar(
589590
title: Text("单词总览"),
591+
actions: [
592+
IconButton(
593+
onPressed: () async {
594+
await showDialog(
595+
context: context,
596+
builder: (context) {
597+
return AlertDialog(
598+
content: Column(
599+
mainAxisSize: MainAxisSize.min,
600+
children: [
601+
StatefulBuilder(
602+
builder: (context, setLocalState) {
603+
return Row(
604+
mainAxisSize: MainAxisSize.min,
605+
children: [
606+
Text("设置固定列数"),
607+
Slider(
608+
min: 0,
609+
max: 5,
610+
divisions: 5,
611+
value: forceColumn.toDouble(),
612+
onChanged: (value){
613+
setLocalState(() {
614+
forceColumn = value.ceil();
615+
});
616+
}
617+
),
618+
SizedBox(width: 60, child: Text(forceColumn == 0 ? "0(自动)" : forceColumn.toString()))
619+
],
620+
);
621+
}
622+
),
623+
],
624+
),
625+
actions: [
626+
ElevatedButton(
627+
onPressed: (){
628+
Navigator.pop(context);
629+
setState(() {}); // 刷新全局状态
630+
},
631+
child: Text("确认")
632+
),
633+
ElevatedButton(
634+
onPressed: (){
635+
Navigator.pop(context);
636+
},
637+
child: Text("取消")
638+
)
639+
],
640+
);
641+
}
642+
);
643+
644+
},
645+
icon: Icon(Icons.view_column)
646+
)
647+
],
590648
),
591649
body: ListView.builder(
592650
physics: allowJsonScorll ? null : NeverScrollableScrollPhysics(),
@@ -623,7 +681,6 @@ class _WordCardOverViewPage extends State<WordCardOverViewPage> {
623681
if(classIndex == context.read<Global>().wordData["Classes"][jsonName].length) {
624682
return SizedBox(height: mediaQuery.size.height); // 避免0.9空间估计不足
625683
}
626-
627684
final String className = context.read<Global>().wordData["Classes"][jsonName].keys.elementAt(classIndex);
628685
return ExpansionTile(
629686
title: Text(className.trim()),
@@ -632,26 +689,39 @@ class _WordCardOverViewPage extends State<WordCardOverViewPage> {
632689
setState(() {
633690
allowClassScorll = !value;
634691
});
635-
classController.animateTo(
636-
(64 * classIndex).toDouble(),
637-
duration: Duration(milliseconds: 200),
638-
curve: StaticsVar.curve
639-
);
692+
if(value) {
693+
classController.animateTo(
694+
(64 * classIndex).toDouble(),
695+
duration: Duration(milliseconds: 200),
696+
curve: StaticsVar.curve
697+
);
698+
jsonController.animateTo(
699+
(66 * (jsonIndex + 1)).toDouble(),
700+
duration: Duration(milliseconds: 200),
701+
curve: StaticsVar.curve
702+
);
703+
} else {
704+
jsonController.animateTo(
705+
(66 * jsonIndex).toDouble(),
706+
duration: Duration(milliseconds: 200),
707+
curve: StaticsVar.curve
708+
);
709+
}
640710
},
641711
children: [
642712
SizedBox(
643713
height: mediaQuery.size.height * 0.8,
644714
child: GridView.builder(
645715
itemCount: context.read<Global>().wordData["Classes"][jsonName][className].length,
646-
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: mediaQuery.size.width ~/ 300),
716+
gridDelegate: forceColumn == 0 ? SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: mediaQuery.size.width ~/ 300) : SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: forceColumn),
647717
itemBuilder: (context, index) {
648718
return Container(
649719
margin: EdgeInsets.all(8.0),
650720
child: WordCard(
651721
word: context.read<Global>().wordData["Words"][context.read<Global>().wordData["Classes"][jsonName][className][index]],
652722
useMask: false,
653-
width: mediaQuery.size.width / (mediaQuery.size.width ~/ 300),
654-
height: mediaQuery.size.width / (mediaQuery.size.width ~/ 300),
723+
width: mediaQuery.size.width / (forceColumn == 0 ? (mediaQuery.size.width ~/ 300) : forceColumn),
724+
height: mediaQuery.size.width / (forceColumn == 0 ? (mediaQuery.size.width ~/ 300) : forceColumn),
655725
),
656726
);
657727
}

0 commit comments

Comments
 (0)