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_screenutil/flutter_screenutil.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/problem_form_page.dart';
class ProblemPage extends StatelessWidget {
class ProblemPage extends GetView<ProblemController> {
const ProblemPage({super.key});
@override
Widget build(BuildContext context) {
final ProblemController problemController = Get.find<ProblemController>();
return DefaultTabController(
initialIndex: 0,
length: 2,
@ -74,58 +72,44 @@ class ProblemPage extends StatelessWidget {
),
),
Expanded(
child: Stack(
children: [
Obx(() {
if (problemController.isLoading.value) {
return Center(
child: CircularProgressIndicator(),
);
child: Obx(() {
if (controller.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,
itemBuilder: (context, index) {
final problem =
problemController.problems[index];
return _buildSwipeableProblemCard(
problem,
problemController,
);
},
//
final problem = controller.problems[index];
return _buildSwipeableProblemCard(
problem,
controller,
);
}),
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(() {
if (problemController.isLoading.value) {
if (controller.isLoading.value) {
return Center(child: CircularProgressIndicator());
}
return ListView.builder(
itemCount: problemController.problems.length,
itemCount: controller.problems.length,
itemBuilder: (context, index) {
final problem = problemController.problems[index];
final problem = controller.problems[index];
return _buildSwipeableProblemCard(
problem,
problemController,
controller,
viewType: ProblemCardViewType.checkbox,
);
},
@ -137,20 +121,46 @@ class ProblemPage extends StatelessWidget {
],
),
),
floatingActionButton: Obx(() {
final bool isOnline = problemController.isOnline.value;
return FloatingActionButton(
heroTag: "abc",
onPressed: isOnline
? () => problemController.uploadAllUnuploaded()
: null,
foregroundColor: Colors.white,
backgroundColor: isOnline ? Colors.red[300] : Colors.grey[400],
child: Icon(
isOnline ? Icons.file_upload_outlined : Icons.cloud_off_outlined,
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: FloatingActionButton(
heroTag: "btn_add",
onPressed: () {
Get.to(() => ProblemFormPage());
},
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