Skip to content

Commit

Permalink
Merge pull request #46 from fga-eps-mds/feat#59/Navbar
Browse files Browse the repository at this point in the history
feat(#59) NavBar inicial
  • Loading branch information
GabrielCostaDeOliveira authored Dec 18, 2024
2 parents c07ba61 + 7fd2366 commit 33c817d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 14 deletions.
17 changes: 5 additions & 12 deletions lib/ui/login/view/LoginView.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:aranduapp/core/log/Log.dart';
import 'package:aranduapp/ui/home/view/HomeView.dart';
import 'package:aranduapp/ui/navbar/view/navBarView.dart';
import 'package:aranduapp/ui/shared/TextAndLink.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -93,12 +93,7 @@ class _LoginState extends State<_Login> {
child: ElevatedButton(
onPressed: () async {
viewModel.loginWithDeviceAuth().then((ok) {
if (ok)
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const HomeView(),
),
);
viewModel.goNextPage();
});
},
child: const Text('Usar senha do celular'),
Expand Down Expand Up @@ -190,11 +185,9 @@ class _LoginState extends State<_Login> {
child: ElevatedButton(
onPressed: () {
viewModel.loginWithEmailAndPassword().then((_) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const HomeView(),
),
);

viewModel.goNextPage();

}).catchError((e) => showDialog<Object>(
context: context,
builder: (BuildContext context) =>
Expand Down
13 changes: 12 additions & 1 deletion lib/ui/login/viewModel/LoginViewModel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:aranduapp/core/log/Log.dart';
import 'package:aranduapp/ui/navbar/view/navBarView.dart';
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
import 'package:aranduapp/ui/login/service/LoginService.dart';
Expand Down Expand Up @@ -46,12 +47,22 @@ class LoginViewModel extends ChangeNotifier {
}

Future<void> getRefreshTokenFuture() async {
await LoginService.refreshToken();
await Future.delayed(const Duration(seconds: 2));

//await LoginService.refreshToken();
}

Future<bool> loginWithDeviceAuth() async {
Log.d('init loginWithDeviceAuth');
return await LocalAuthentication()
.authenticate(localizedReason: 'Toque com o dedo no sensor para logar');
}

void goNextPage() {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const NavbarView(),
),
);
}
}
12 changes: 12 additions & 0 deletions lib/ui/navbar/model/navBarViewModel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/material.dart';

class NavbarViewModel extends ChangeNotifier {
int _selectedIndex = 0;

int get selectedIndex => _selectedIndex;

void changeTab(int index) {
_selectedIndex = index;
notifyListeners();
}
}
58 changes: 58 additions & 0 deletions lib/ui/navbar/view/navBarView.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:aranduapp/ui/home/view/HomeView.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:aranduapp/ui/navbar/model/navBarViewModel.dart';

class NavbarView extends StatelessWidget {
const NavbarView({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
body: ChangeNotifierProvider(
create: (context) => NavbarViewModel(),
builder: (context, child) {
return page(context);
}),
);
}
}

Widget page(BuildContext context) {
NavbarViewModel viewModel = Provider.of<NavbarViewModel>(context);

final List<Widget> pages = [
const HomeView(),
const Center(child: Text('Friends', style: TextStyle(fontSize: 20))),
const Center(child: Text('Dashbord', style: TextStyle(fontSize: 20))),
const Center(child: Text('Profile', style: TextStyle(fontSize: 20))),
];

return Scaffold(
body: pages[viewModel.selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: viewModel.selectedIndex,
onTap: viewModel.changeTab,
selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor:Theme.of(context).colorScheme.onSurface,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.groups_outlined),
label: "Amigos",
),
BottomNavigationBarItem(
icon: Icon(Icons.bar_chart),
label: "Dashboard",
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: "Perfil",
),
],
),
);
}
2 changes: 1 addition & 1 deletion lib/ui/welcome/view/WelcomeView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WelcomeView extends StatelessWidget {
onTap: () => {


Navigator.of(context).push(
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const OnboardingView(),
),
Expand Down

0 comments on commit 33c817d

Please sign in to comment.