Skip to content

Commit

Permalink
edit bottom navbar handle click, refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
12henbx committed Dec 4, 2023
1 parent 60ac905 commit 3af7b57
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 159 deletions.
69 changes: 22 additions & 47 deletions app/lib/core/bases/widgets/layout/bottom_navbar.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import 'dart:ui';

// import 'package:artefak/services/auth.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
// import 'package:artefak/widgets/auth_sliding_panel.dart';

class BottomNavBar extends StatefulWidget {
const BottomNavBar({
Key? key,
super.key,
required this.currentIndex,
}) : super(key: key);
});

final int currentIndex;

Expand All @@ -18,22 +15,21 @@ class BottomNavBar extends StatefulWidget {
}

class _BottomNavBarState extends State<BottomNavBar> {
int _currentIndex = 0; // To track the selected menu item
// To track the selected menu item
int _currentIndex = 0;
void _onTap(int index, BuildContext context) {
switch (index) {
case 0:
Navigator.popUntil(context, ModalRoute.withName('/'));
Navigator.popUntil(context, ModalRoute.withName('/main'));
break;
case 1:
Navigator.pushNamed(context, '/collection');
Navigator.pushNamed(context, '/setting');
break;
}
}

@override
Widget build(BuildContext context) {
ThemeData _themeData = Theme.of(context);

// Update the selected menu item index and rebuild the widget
void _updateIndex(int newIndex) {
setState(() {
Expand All @@ -44,88 +40,67 @@ class _BottomNavBarState extends State<BottomNavBar> {
// Custom method to build IconButton with color change based on selection
Widget _buildIconButton(IconData icon, String label, int index) {
return SizedBox.fromSize(
size: Size(80, 56),
size: const Size(80, 56),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {},
onTap: () {
_updateIndex(index);
_onTap(index, context);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FaIcon(
icon,
color: _currentIndex == index ? Colors.blue : Colors.grey,
color: _currentIndex == index ? const Color(0xFF1BB8E1) : Colors.grey,
),
SizedBox(
const SizedBox(
height: 5,
),
Text(
label,
style: TextStyle(
fontSize: 11.0,
color: _currentIndex == index ? Colors.blue : Colors.grey,
fontSize: 11,
color: _currentIndex == index ? const Color(0xFF1BB8E1) : Colors.grey,
),
),
],
),
),
),
);
// return IconButton(
// icon: FaIcon(
// icon,
// color: _currentIndex == index ? Colors.blue : Colors.grey,
// ),
// onPressed: () {
// _updateIndex(index);
// },
// );
}

return ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 30.0,
sigmaY: 30.0,
sigmaX: 30,
sigmaY: 30,
),
child: SizedBox(
height: 60,
child: BottomAppBar(
elevation: 2,
// items: <BottomNavigationBarItem>[
shape: const CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildIconButton(FontAwesomeIcons.fileLines, "Materi", 0),
_buildIconButton(FontAwesomeIcons.fileLines, 'Materi', 0),
Container(
margin: const EdgeInsets.only(
bottom: 9.0,
bottom: 9,
),
alignment: Alignment.bottomCenter,
child: Text(
child: const Text(
"Latihan",
style: TextStyle(fontSize: 11.0),
style: TextStyle(fontSize: 11),
),
),
_buildIconButton(FontAwesomeIcons.gear, "Pengaturan", 1),
// IconButton(
// onPressed: () {
// _updateIndex(0);
// },
// icon: const FaIcon(FontAwesomeIcons.fileLines),
// ),
// IconButton(
// onPressed: () {
// _updateIndex(1);
// },
// icon: const FaIcon(FontAwesomeIcons.gear),
// ),
_buildIconButton(FontAwesomeIcons.gear, 'Pengaturan', 1),
],
),
// currentIndex: currentIndex,
// onTap: (index) => _onTap(index, context),
),
),
),
Expand Down
98 changes: 8 additions & 90 deletions app/lib/features/main/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class _HomePageState extends State<HomePage> {
ClipPath(
clipper: ClipPathClass(),
child: Container(
height: 250.0,
color: Color(0xFF1BB8E1),
height: 250,
color: const Color(0xFF1BB8E1),
),
),
Column(
Expand Down Expand Up @@ -84,112 +84,30 @@ class _HomePageState extends State<HomePage> {
items: imgList
.map((item) => Container(
margin: const EdgeInsets.only(
left: 10.0,
right: 10.0,
left: 10,
right: 10,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.network(item, fit: BoxFit.cover, width: 300.0,),
borderRadius: BorderRadius.circular(10),
child: Image.network(item, fit: BoxFit.cover, width: 300,),
),
))
.toList(),
options: CarouselOptions(
height: 150,
aspectRatio: 16 / 9,
viewportFraction: 1,
initialPage: 0,
enableInfiniteScroll: true,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
// enlargeCenterPage: true,
// enlargeFactor: 0.3,
// onPageChanged: callbackFunction,
scrollDirection: Axis.horizontal,
autoPlayInterval: const Duration(seconds: 3),
),
),
],
),
),
// Expanded(
// child: SingleChildScrollView(
// child: Column(
// children: [
const MaterialMenu(),
// Button(
// onTap: () async {
// final url = Uri.parse(
// 'https://bebras.or.id/v3/bebras-indonesia-challenge-2023/',
// );
// if (!await launchUrl(url)) {
// throw Exception('Could not launch $url');
// }
// },
// customButtonColor: Colors.blue,
// customTextColor: Colors.white,
// text: 'ℹ️ Tentang Tantangan Bebras ℹ️',
// ),
// const SizedBox(
// height: 25,
// ),
// Button(
// buttonType: ButtonType.primary,
// onTap: () async {
// await context.push('/material');
// },
// text: 'Lihat / Cetak Materi',
// ),
// const SizedBox(
// height: 25,
// ),
// Button(
// buttonType: ButtonType.primary,
// onTap: () async {
// await context.push('/quiz_registration');
// },
// text: 'Ikut Latihan Mingguan',
// ),
// const SizedBox(
// height: 25,
// ),
// Button(
// onTap: () async {
// await context.push('/setting');
// },
// customButtonColor: Colors.grey,
// customTextColor: Colors.white,
// text: 'Pengaturan',
// ),
// SizedBox(
// height: 120,
// ),
// InkWell(
// onTap: () async {
// final url = Uri.parse(
// 'https://tlx.toki.id/',
// );
// if (!await launchUrl(url)) {
// throw Exception('Could not launch $url');
// }
// },
// child: Center(
// child: Text(
// 'From Ikatan Alumni TOKI with ❤️',
// textAlign: TextAlign.center,
// style: FontTheme.greyNormal14(),
// ),
// ),
// ),
// ],
// ),
// ),
// ),
],
),
],
Expand All @@ -199,7 +117,7 @@ class _HomePageState extends State<HomePage> {
onPressed: () {},
child: const FaIcon(FontAwesomeIcons.graduationCap),
),
bottomNavigationBar: BottomNavBar(
bottomNavigationBar: const BottomNavBar(
currentIndex: 0,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class _MaterialMenuState extends State<MaterialMenu> {
),
child: OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor: filterIndex == index ? Colors.blue : Colors.white,
side: BorderSide(
backgroundColor: filterIndex == index ? const Color(0xFF1BB8E1) : Colors.white,
side: const BorderSide(
width: 1,
color: Color(0xFF1BB8E1),
),
Expand Down Expand Up @@ -106,7 +106,7 @@ class _MaterialMenuState extends State<MaterialMenu> {
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 4,
offset: Offset(0, 3), // changes position of shadow
offset: const Offset(0, 3), // changes position of shadow
),
],
),
Expand All @@ -131,7 +131,7 @@ class _MaterialMenuState extends State<MaterialMenu> {
icon: const Icon(
Icons.print_rounded,
size: 28,
color: Colors.blue,
color: Color(0xFF1BB8E1),
),
iconSize: 28,
),
Expand All @@ -143,26 +143,14 @@ class _MaterialMenuState extends State<MaterialMenu> {

@override
Widget build(BuildContext context) {
return
// BebrasScaffold(
// avoidBottomInset: false,
// body: Padding(
// padding: const EdgeInsets.only(top: 10),
// child:
Stack(
return Stack(
children: [
Container(
padding: const EdgeInsets.only(
left: 25.0,
),
child: Column(
children: [
// Image.asset(
// Assets.bebrasPandaiText,
// ),
// const SizedBox(
// height: 30,
// ),
SizedBox(
height: 40,
width: MediaQuery.of(context).size.width - 10,
Expand Down Expand Up @@ -207,14 +195,16 @@ class _MaterialMenuState extends State<MaterialMenu> {
return const Text('Something went wrong');
}

if (snapshot.connectionState == ConnectionState.waiting) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
}

var displayEmpty = true;
final boxHeight = MediaQuery.of(context).size.height - 456; // TODO: set the safe number to be the box height
final boxHeight = MediaQuery.of(context).size.height -
456; // TODO: set the safe number to be the box height
return SingleChildScrollView(
child: SizedBox(
height: boxHeight,
Expand All @@ -241,7 +231,7 @@ class _MaterialMenuState extends State<MaterialMenu> {
offset: const Offset(
0,
-10,
), // Set the desired offset
),
child: Container(
height: boxHeight,
padding: const EdgeInsets.all(10),
Expand Down Expand Up @@ -274,8 +264,6 @@ class _MaterialMenuState extends State<MaterialMenu> {
),
],
);
// ),
// );
}

// PDF print
Expand Down

0 comments on commit 3af7b57

Please sign in to comment.