Skip to content

Commit

Permalink
Merge pull request #3 from mirmoktadir/orientation
Browse files Browse the repository at this point in the history
update navbar and orientation
  • Loading branch information
mirmoktadir authored Jul 9, 2023
2 parents 65cd853 + 7d7f505 commit 33e125d
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 155 deletions.
224 changes: 107 additions & 117 deletions lib/app/components/navbar/bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,146 +2,136 @@

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:getx_standard/app/modules/home/views/home_view.dart';
import 'package:get/get.dart';
import 'package:iconly/iconly.dart';

import '../../modules/Graphql/views/graphql_view.dart';
import 'navbar_controller.dart';

class BottomNavbar extends StatelessWidget {
BottomNavbar({Key? key}) : super(key: key);

List navigation = [
const HomeView(),
const GraphQLView(),
];
int _selectedIndex = 0;
class BottomNavbar extends GetView<NavbarController> {
const BottomNavbar({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
void _onTap(int index) {
_selectedIndex = index;

(context as Element).markNeedsBuild();
}

return Scaffold(
resizeToAvoidBottomInset: false,
extendBody: true,
body: navigation[_selectedIndex],
bottomNavigationBar: Stack(
children: [
Positioned(
bottom: 35.h,
left: 0,
right: 0,
child: Container(
width: MediaQuery.of(context).size.width,
height: 80.h,
decoration: BoxDecoration(
color: theme.primaryColor,
borderRadius: BorderRadius.circular(50.r),
boxShadow: [
BoxShadow(
color: theme.colorScheme.secondary.withOpacity(1),
spreadRadius: 0,
blurRadius: 20.r),
],
),
margin: EdgeInsets.symmetric(horizontal: 65.w),
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 75.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
/// ITEM 1
Column(
mainAxisAlignment: MainAxisAlignment.center,
body: Obx(() => controller.navigation[controller.selectedIndex.value]),
bottomNavigationBar: Obx(() => Stack(
children: [
Positioned(
bottom: 35.h,
left: 0,
right: 0,
child: Container(
width: MediaQuery.of(context).size.width,
height: 80.h,
decoration: BoxDecoration(
color: theme.primaryColor,
borderRadius: BorderRadius.circular(50.r),
boxShadow: [
BoxShadow(
color: theme.colorScheme.secondary.withOpacity(1),
spreadRadius: 0,
blurRadius: 20.r),
],
),
margin: EdgeInsets.symmetric(horizontal: 65.w),
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 75.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 40.h,
width: 40.w,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
splashFactory: NoSplash.splashFactory,
backgroundColor: Colors.transparent,
/// ITEM 1
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 40.h,
width: 40.w,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
splashFactory: NoSplash.splashFactory,
backgroundColor: Colors.transparent,
),
onPressed: () {
controller.onTap(0);
},
child: Center(
child: Icon(
controller.selectedIndex.value == 0
? IconlyBold.home
: IconlyLight.home,
color: Colors.white,
size: 32,
),
),
),
),
onPressed: () {
_onTap(0);
},
child: Center(
child: Icon(
_selectedIndex == 0
? IconlyBold.home
: IconlyLight.home,
color: Colors.white,
size: 32,
const SizedBox(height: 3),
Container(
height: 8,
width: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: controller.selectedIndex.value == 0
? Colors.white
: Colors.transparent,
),
),
),
),
const SizedBox(height: 3),
Container(
height: 8,
width: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _selectedIndex == 0
? Colors.white
: Colors.transparent,
),
],
),
],
),

/// ITEM 2
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 40.h,
width: 40.w,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
splashFactory: NoSplash.splashFactory,
backgroundColor: Colors.transparent,
/// ITEM 2
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 40.h,
width: 40.w,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
splashFactory: NoSplash.splashFactory,
backgroundColor: Colors.transparent,
),
onPressed: () {
controller.onTap(1);
},
child: Center(
child: Icon(
controller.selectedIndex.value == 1
? IconlyBold.graph
: IconlyLight.graph,
color: Colors.white,
size: 32,
),
),
),
),
onPressed: () {
_onTap(1);
},
child: Center(
child: Icon(
_selectedIndex == 1
? IconlyBold.graph
: IconlyLight.graph,
color: Colors.white,
size: 32,
const SizedBox(height: 3),
Container(
height: 8,
width: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: controller.selectedIndex.value == 1
? Colors.white
: Colors.transparent,
),
),
),
),
const SizedBox(height: 3),
Container(
height: 8,
width: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _selectedIndex == 1
? Colors.white
: Colors.transparent,
),
],
),
],
),
],
),
),
),
),
),
],
),
],
)),
);
}
}
}
10 changes: 7 additions & 3 deletions lib/app/components/navbar/navbar_binding.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:get/get.dart';
import 'package:getx_standard/app/modules/home/controllers/home_controller.dart';

import '../../modules/Graphql/controllers/graphql_controller.dart';
import '../../modules/home-with-graphql/controllers/graphql_controller.dart';
import '../../modules/home-with-restAPI/controllers/home_controller.dart';
import 'navbar_controller.dart';

class NavbarBinding extends Bindings {
@override
Expand All @@ -12,5 +13,8 @@ class NavbarBinding extends Bindings {
Get.lazyPut<GraphQLController>(
() => GraphQLController(),
);
Get.lazyPut<NavbarController>(
() => NavbarController(),
);
}
}
}
16 changes: 16 additions & 0 deletions lib/app/components/navbar/navbar_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:get/get.dart';

import '../../modules/home-with-graphql/views/graphql_view.dart';
import '../../modules/home-with-restAPI/views/home_view.dart';

class NavbarController extends GetxController {
List navigation = [
const HomeView(),
const GraphQLView(),
];
RxInt selectedIndex = 0.obs;

void onTap(int index) {
selectedIndex.value = index;
}
}
5 changes: 1 addition & 4 deletions lib/app/data/local/my_shared_pref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MySharedPref {
// prevent making instance
MySharedPref._();

// get storage
// shared pref init
static late SharedPreferences _sharedPreferences;

static Future<void> init() async {
Expand All @@ -22,9 +22,6 @@ class MySharedPref {
static const String _currentLocalKey = 'current_local';
static const String _lightThemeKey = 'is_theme_light';




/// set theme current type as light theme
static void setThemeIsLight(bool lightTheme) =>
_sharedPreferences.setBool(_lightThemeKey, lightTheme);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:getx_standard/app/components/navbar/navbar_controller.dart';
import 'package:iconly/iconly.dart';

import '../../../../config/theme/my_fonts.dart';
import '../../../components/empty_widget.dart';
import '../controllers/graphql_controller.dart';

class GraphQLView extends GetView<GraphQLController> {
const GraphQLView({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
final navController = Get.put(NavbarController());
return Scaffold(
appBar: AppBar(
title: const Text('GraphQL'),
actions: [
IconButton(
onPressed: () => navController.selectedIndex.value = 0,
icon: const Icon(
IconlyBold.home,
color: Colors.white,
)),
],
centerTitle: true,
),
body: Obx(() => controller.isError.value == true
Expand Down Expand Up @@ -98,4 +110,4 @@ class GraphQLView extends GetView<GraphQLController> {
)),
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import 'package:get/get.dart';
import 'package:getx_standard/app/modules/home/bindings/home_binding.dart';
import 'package:getx_standard/app/modules/home/views/post_detail_view.dart';

import '../../../service/REST/api_urls.dart';
import '../../../service/REST/dio_client.dart';
import '../../../service/handler/exception_handler.dart';
import '../bindings/home_binding.dart';
import '../model/posts.dart';
import '../views/post_detail_view.dart';

class HomeController extends GetxController with ExceptionHandler {


///GET POST LIST
final postList = RxList<Posts>();

getPostList() async {
showLoading();

var response =
await DioClient().get(url: ApiUrl.allPosts).catchError(handleError);
await DioClient().get(url: ApiUrl.allPosts).catchError(handleError);

if (response == null) return;

Expand Down Expand Up @@ -50,4 +52,4 @@ class HomeController extends GetxController with ExceptionHandler {

super.onReady();
}
}
}
File renamed without changes.
Loading

0 comments on commit 33e125d

Please sign in to comment.