Browse Source

refactor : 问题页悬浮按钮

dev
徐振升 2 weeks ago
parent
commit
5020451a84
  1. 118
      lib/modules/problem/views/problem_page.dart

118
lib/modules/problem/views/problem_page.dart

@ -1,4 +1,3 @@
// problem_page.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -8,12 +7,11 @@ import 'package:problem_check_system/modules/problem/views/widgets/date_picker_b
import 'package:problem_check_system/modules/problem/views/widgets/problem_card.dart'; import 'package:problem_check_system/modules/problem/views/widgets/problem_card.dart';
import 'package:problem_check_system/modules/problem/views/problem_form_page.dart'; import 'package:problem_check_system/modules/problem/views/problem_form_page.dart';
class ProblemPage extends StatelessWidget { class ProblemPage extends GetView<ProblemController> {
const ProblemPage({super.key}); const ProblemPage({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ProblemController problemController = Get.find<ProblemController>();
return DefaultTabController( return DefaultTabController(
initialIndex: 0, initialIndex: 0,
length: 2, length: 2,
@ -74,58 +72,44 @@ class ProblemPage extends StatelessWidget {
), ),
), ),
Expanded( Expanded(
child: Stack( child: Obx(() {
children: [ if (controller.isLoading.value) {
Obx(() { return Center(child: CircularProgressIndicator());
if (problemController.isLoading.value) { }
return Center(
child: CircularProgressIndicator(), return ListView.builder(
); // +1
itemCount: controller.problems.length + 1,
itemBuilder: (context, index) {
// SizedBox
if (index == controller.problems.length) {
return SizedBox(height: 79.5.h);
} }
return ListView.builder( //
itemCount: problemController.problems.length, final problem = controller.problems[index];
itemBuilder: (context, index) { return _buildSwipeableProblemCard(
final problem = problem,
problemController.problems[index]; controller,
return _buildSwipeableProblemCard(
problem,
problemController,
);
},
); );
}), },
Positioned( );
bottom: 5.h, }),
right: 160.5.w,
child: FloatingActionButton(
heroTag: "123",
onPressed: () {
Get.to(() => ProblemFormPage());
},
shape: CircleBorder(),
backgroundColor: Colors.blue[300],
foregroundColor: Colors.white,
child: const Icon(Icons.add),
),
),
],
),
), ),
], ],
), ),
Obx(() { Obx(() {
if (problemController.isLoading.value) { if (controller.isLoading.value) {
return Center(child: CircularProgressIndicator()); return Center(child: CircularProgressIndicator());
} }
return ListView.builder( return ListView.builder(
itemCount: problemController.problems.length, itemCount: controller.problems.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final problem = problemController.problems[index]; final problem = controller.problems[index];
return _buildSwipeableProblemCard( return _buildSwipeableProblemCard(
problem, problem,
problemController, controller,
viewType: ProblemCardViewType.checkbox, viewType: ProblemCardViewType.checkbox,
); );
}, },
@ -137,20 +121,46 @@ class ProblemPage extends StatelessWidget {
], ],
), ),
), ),
floatingActionButton: Obx(() { floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
final bool isOnline = problemController.isOnline.value; floatingActionButton: Stack(
return FloatingActionButton( children: [
heroTag: "abc", Align(
onPressed: isOnline alignment: Alignment.bottomCenter,
? () => problemController.uploadAllUnuploaded() child: FloatingActionButton(
: null, heroTag: "btn_add",
foregroundColor: Colors.white, onPressed: () {
backgroundColor: isOnline ? Colors.red[300] : Colors.grey[400], Get.to(() => ProblemFormPage());
child: Icon( },
isOnline ? Icons.file_upload_outlined : Icons.cloud_off_outlined, shape: CircleBorder(),
backgroundColor: Colors.blue[300],
foregroundColor: Colors.white,
child: const Icon(Icons.add),
),
), ),
); Positioned(
}), bottom: 56.h, // 100
right: 27.w, // 16
child: Obx(() {
final bool isOnline = controller.isOnline.value;
return FloatingActionButton(
heroTag: "btn_upload",
onPressed: isOnline
? () => controller.uploadAllUnuploaded()
: null,
foregroundColor: Colors.white,
backgroundColor: isOnline
? Colors.red[300]
: Colors.grey[400],
child: Icon(
isOnline
? Icons.file_upload_outlined
: Icons.cloud_off_outlined,
),
);
}),
),
],
),
), ),
); );
} }

Loading…
Cancel
Save