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. 89
      lib/modules/home/views/home_page.dart

2
lib/app/bindings/initial_binding.dart

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

10
lib/main.dart

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

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

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

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

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:problem_check_system/modules/home/controllers/home_controller.dart'; import 'package:problem_check_system/modules/home/controllers/home_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class HomePage extends GetView<HomeController> { class HomePage extends GetView<HomeController> {
const HomePage({super.key}); const HomePage({super.key});
@ -9,28 +10,88 @@ class HomePage extends GetView<HomeController> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Obx( return Obx(
() => Scaffold( () => Scaffold(
body: controller.pages[controller.selectedIndex.value], // body: controller.pages[controller.selectedIndex.value],
bottomNavigationBar: NavigationBar( bottomNavigationBar: _buildCustomBottomBar(),
selectedIndex: controller.selectedIndex.value, ),
onDestinationSelected: controller.changeIndex, // );
destinations: const [ }
// NavigationDestination(
// icon: Icon(Icons.home_outlined), Widget _buildCustomBottomBar() {
// selectedIcon: Icon(Icons.home), 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: '首页', // label: '首页',
// ), // ),
NavigationDestination( _buildBottomBarItem(
icon: Icon(Icons.description_outlined), index: 0,
selectedIcon: Icon(Icons.description), icon: Icons.description_outlined,
activeIcon: Icons.description,
label: '问题', label: '问题',
), ),
NavigationDestination( _buildBottomBarItem(
icon: Icon(Icons.person_outline), index: 1,
selectedIcon: Icon(Icons.person), icon: Icons.person_outlined,
activeIcon: Icons.person,
label: '我的', 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