Browse Source

feat : 自定义bottomBar

dev
徐振升 3 weeks ago
parent
commit
e363c8bacb
  1. 2
      lib/app/bindings/initial_binding.dart
  2. 10
      lib/main.dart
  3. 8
      lib/modules/auth/views/login_page.dart
  4. 103
      lib/modules/home/views/home_page.dart

2
lib/app/bindings/initial_binding.dart

@ -20,12 +20,12 @@ class InitialBinding implements Bindings {
void _registerCoreServices() {
///
Get.put(UpgraderService());
Get.put<GetStorage>(GetStorage(), permanent: true);
Get.put<Uuid>(Uuid(), permanent: true);
Get.put<HttpProvider>(HttpProvider());
Get.put<SQLiteProvider>(SQLiteProvider());
Get.put<ConnectivityProvider>(ConnectivityProvider());
Get.put(UpgraderService());
}
void _registerRepositories() {

10
lib/main.dart

@ -11,11 +11,11 @@ import 'package:flutter_localizations/flutter_localizations.dart';
void main() async {
// Flutter Binding
WidgetsFlutterBinding.ensureInitialized();
//
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
// //
// SystemChrome.setPreferredOrientations([
// DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown,
// ]);
// GetStorage
await GetStorage.init();
// Add this line

8
lib/modules/auth/views/login_page.dart

@ -33,8 +33,8 @@ class LoginPage extends GetView<LoginController> {
child: Image.asset(
'assets/images/label.png',
width: 171.5.w,
height: 23.5.h,
fit: BoxFit.fitWidth,
// height: 23.5.h,
fit: BoxFit.cover,
),
),
SizedBox(height: 15.5.h),
@ -43,8 +43,8 @@ class LoginPage extends GetView<LoginController> {
child: Image.asset(
'assets/images/label1.png',
width: 296.5.w,
height: 35.5.h,
fit: BoxFit.fitWidth,
// height: 35.5.h,
fit: BoxFit.cover,
),
),
SizedBox(height: 56.5.h),

103
lib/modules/home/views/home_page.dart

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:problem_check_system/modules/home/controllers/home_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class HomePage extends GetView<HomeController> {
const HomePage({super.key});
@ -9,27 +10,87 @@ class HomePage extends GetView<HomeController> {
Widget build(BuildContext context) {
return Obx(
() => Scaffold(
body: controller.pages[controller.selectedIndex.value], //
bottomNavigationBar: NavigationBar(
selectedIndex: controller.selectedIndex.value,
onDestinationSelected: controller.changeIndex, //
destinations: const [
// NavigationDestination(
// icon: Icon(Icons.home_outlined),
// selectedIcon: Icon(Icons.home),
// label: '首页',
// ),
NavigationDestination(
icon: Icon(Icons.description_outlined),
selectedIcon: Icon(Icons.description),
label: '问题',
),
NavigationDestination(
icon: Icon(Icons.person_outline),
selectedIcon: Icon(Icons.person),
label: '我的',
),
],
body: controller.pages[controller.selectedIndex.value],
bottomNavigationBar: _buildCustomBottomBar(),
),
);
}
Widget _buildCustomBottomBar() {
return Container(
height: 60.h, //
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withAlpha(76),
blurRadius: 8,
offset: const Offset(0, -2),
),
],
),
child: Row(
children: [
//
// _buildBottomBarItem(
// index: 0,
// icon: Icons.home_outlined,
// activeIcon: Icons.home,
// label: '首页',
// ),
_buildBottomBarItem(
index: 0,
icon: Icons.description_outlined,
activeIcon: Icons.description,
label: '问题',
),
_buildBottomBarItem(
index: 1,
icon: Icons.person_outlined,
activeIcon: Icons.person,
label: '我的',
),
],
),
);
}
Widget _buildBottomBarItem({
required int index,
required IconData icon,
required IconData activeIcon,
required String label,
}) {
bool isSelected = controller.selectedIndex.value == index;
return Expanded(
child: GestureDetector(
onTap: () => controller.changeIndex(index),
child: Container(
color: Colors.transparent, //
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
isSelected ? activeIcon : icon,
color: isSelected
? const Color(0xFF418CFC)
: Colors.grey.shade600,
size: 24.w,
),
SizedBox(width: 4.w), //
Text(
label,
style: TextStyle(
fontSize: 14.sp,
color: isSelected
? const Color(0xFF418CFC)
: Colors.grey.shade600,
fontWeight: isSelected ? FontWeight.w500 : FontWeight.normal,
),
),
],
),
),
),
);

Loading…
Cancel
Save