mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
Implemented Navigation
This commit is contained in:
@ -1,3 +1,24 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/home/view/home_view.dart';
|
||||||
|
import 'package:syncrow_app/features/profile/view/profile_view.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
|
import 'package:syncrow_app/features/smart/view/smart_view.dart';
|
||||||
|
|
||||||
class SceneProvider extends ChangeNotifier {}
|
class HomeProvider extends ChangeNotifier {
|
||||||
|
int pageIndex = 0;
|
||||||
|
|
||||||
|
final List<Widget> pages = [
|
||||||
|
const HomeView(),
|
||||||
|
const SceneView(),
|
||||||
|
const SmartView(),
|
||||||
|
const ProfileView(),
|
||||||
|
];
|
||||||
|
|
||||||
|
//get current page
|
||||||
|
Widget get currentPage => pages[pageIndex];
|
||||||
|
|
||||||
|
void updatePageIndex(int index, BuildContext context) {
|
||||||
|
pageIndex = index;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
15
lib/features/home/view/default_app_bar.dart
Normal file
15
lib/features/home/view/default_app_bar.dart
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
|
const DefaultAppBar({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AppBar(
|
||||||
|
title: const Text('Syncrow'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Size get preferredSize => const Size.fromHeight(50);
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:syncrow_app/features/home/provider/provider.dart';
|
import 'package:syncrow_app/features/home/provider/provider.dart';
|
||||||
|
import 'package:syncrow_app/features/home/view/default_app_bar.dart';
|
||||||
|
import 'package:syncrow_app/features/home/view/home_view_body.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_nav_bar.dart';
|
||||||
|
|
||||||
class HomeView extends StatelessWidget {
|
class HomeView extends StatelessWidget {
|
||||||
const HomeView({super.key});
|
const HomeView({super.key});
|
||||||
@ -8,46 +11,17 @@ class HomeView extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return ChangeNotifierProvider(
|
||||||
create: (BuildContext context) => SceneProvider(),
|
create: (BuildContext context) => HomeProvider(),
|
||||||
builder: (context, child) => Scaffold(
|
builder: (context, child) => Consumer<HomeProvider>(
|
||||||
appBar: AppBar(
|
builder: (context, provider, child) {
|
||||||
title: const Text('Syncrow'),
|
return Scaffold(
|
||||||
),
|
appBar: const DefaultAppBar(),
|
||||||
body: const Center(
|
body: provider.pageIndex == 0
|
||||||
child: Text('Home'),
|
? const HomeViewBody()
|
||||||
),
|
: provider.currentPage,
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: const DefaultNavBar(),
|
||||||
items: const [
|
);
|
||||||
BottomNavigationBarItem(
|
},
|
||||||
icon: Icon(
|
|
||||||
Icons.home_outlined,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
label: 'Home',
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.view_in_ar,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
label: 'Scene',
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.smart_toy_outlined,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
label: 'Smart',
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.account_circle,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
label: 'Account',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
14
lib/features/home/view/home_view_body.dart
Normal file
14
lib/features/home/view/home_view_body.dart
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class HomeViewBody extends StatelessWidget {
|
||||||
|
const HomeViewBody({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Center(
|
||||||
|
child: Text('Home'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -10,13 +10,9 @@ class ProfileView extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return ChangeNotifierProvider(
|
||||||
create: (BuildContext context) => ProfileProvider(),
|
create: (BuildContext context) => ProfileProvider(),
|
||||||
builder: (context, child) => _buildPage(context),
|
builder: (context, child) => const Center(
|
||||||
|
child: Text('Profile'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPage(BuildContext context) {
|
|
||||||
final provider = context.read<ProfileProvider>();
|
|
||||||
|
|
||||||
return Container();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:syncrow_app/features/home/provider/provider.dart';
|
|
||||||
|
|
||||||
class SceneView extends StatelessWidget {
|
class SceneView extends StatelessWidget {
|
||||||
const SceneView({super.key});
|
const SceneView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return const Center(
|
||||||
create: (BuildContext context) => SceneProvider(),
|
child: Text('Scene'),
|
||||||
builder: (context, child) => _buildPage(context),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPage(BuildContext context) {
|
|
||||||
final provider = context.read<SceneProvider>();
|
|
||||||
|
|
||||||
return Container();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
58
lib/features/shared_widgets/default_nav_bar.dart
Normal file
58
lib/features/shared_widgets/default_nav_bar.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:syncrow_app/features/home/provider/provider.dart';
|
||||||
|
|
||||||
|
class DefaultNavBar extends StatelessWidget {
|
||||||
|
const DefaultNavBar({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ChangeNotifierProvider(
|
||||||
|
create: (BuildContext context) => HomeProvider(),
|
||||||
|
child: BottomNavigationBar(
|
||||||
|
onTap: (int index) {
|
||||||
|
context.read<HomeProvider>().updatePageIndex(index, context);
|
||||||
|
},
|
||||||
|
currentIndex: context.watch<HomeProvider>().pageIndex,
|
||||||
|
selectedIconTheme: const IconThemeData(
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
selectedLabelStyle: const TextStyle(
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
items: const [
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.home_outlined,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
label: 'Home',
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.view_in_ar,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
label: 'Scene',
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.smart_toy_outlined,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
label: 'Smart',
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.account_circle,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
label: 'Account',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -10,13 +10,9 @@ class SmartView extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return ChangeNotifierProvider(
|
||||||
create: (BuildContext context) => SmartProvider(),
|
create: (BuildContext context) => SmartProvider(),
|
||||||
builder: (context, child) => _buildPage(context),
|
builder: (context, child) => const Center(
|
||||||
|
child: Text('Smart'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPage(BuildContext context) {
|
|
||||||
final provider = context.read<SmartProvider>();
|
|
||||||
|
|
||||||
return Container();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
29
lib/features/splash/splash_view.dart
Normal file
29
lib/features/splash/splash_view.dart
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/navigation/route_manager.dart';
|
||||||
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
|
|
||||||
|
class SplashView extends StatelessWidget {
|
||||||
|
const SplashView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_forward),
|
||||||
|
onPressed: () {
|
||||||
|
RouteManager().routerManagerPopAndPushNamed(
|
||||||
|
routeName: Routes.homeRoute,
|
||||||
|
context: context,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: const Center(
|
||||||
|
child: Text('Splash Screen'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
title: 'Syncrow App',
|
title: 'Syncrow App',
|
||||||
onGenerateRoute: router.Router.generateRoute,
|
onGenerateRoute: router.Router.generateRoute,
|
||||||
initialRoute: RouteConstants.homeRoute,
|
initialRoute: Routes.splash,
|
||||||
themeMode: ThemeMode.system,
|
themeMode: ThemeMode.system,
|
||||||
supportedLocales: const [
|
supportedLocales: const [
|
||||||
Locale('en', ''), // English, no country code
|
Locale('en', ''), // English, no country code
|
||||||
|
@ -4,17 +4,17 @@ import 'routing_constants.dart';
|
|||||||
|
|
||||||
class RouteManager {
|
class RouteManager {
|
||||||
List<String> routesWithoutLogin = [
|
List<String> routesWithoutLogin = [
|
||||||
RouteConstants.homeRoute,
|
Routes.homeRoute,
|
||||||
];
|
];
|
||||||
|
|
||||||
List<String> exclusionList = [];
|
List<String> exclusionList = [];
|
||||||
|
|
||||||
|
//TODO (to mohammad) add the context extension
|
||||||
routerManager({required String routeName, required BuildContext context}) {
|
routerManager({required String routeName, required BuildContext context}) {
|
||||||
Navigator.of(context).pushNamed(routeName);
|
Navigator.of(context).pushNamed(routeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
routerManagerPushUntil(
|
routerManagerPushUntil(BuildContext? context, {required String routeName}) {
|
||||||
{required String routeName, required BuildContext? context}) {
|
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.pushNamedAndRemoveUntil(routeName, (route) => false);
|
.pushNamedAndRemoveUntil(routeName, (route) => false);
|
||||||
|
@ -1,16 +1,35 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_app/features/home/view/home_view.dart';
|
import 'package:syncrow_app/features/home/view/home_view.dart';
|
||||||
|
import 'package:syncrow_app/features/profile/view/profile_view.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
|
import 'package:syncrow_app/features/smart/view/smart_view.dart';
|
||||||
|
import 'package:syncrow_app/features/splash/splash_view.dart';
|
||||||
|
|
||||||
import 'routing_constants.dart';
|
import 'routing_constants.dart';
|
||||||
|
|
||||||
class Router {
|
class Router {
|
||||||
static Route<dynamic> generateRoute(RouteSettings settings) {
|
static Route<dynamic> generateRoute(RouteSettings settings) {
|
||||||
switch (settings.name) {
|
switch (settings.name) {
|
||||||
case RouteConstants.homeRoute:
|
case Routes.splash:
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const SplashView(), settings: settings);
|
||||||
|
|
||||||
|
case Routes.homeRoute:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => const HomeView(), settings: settings);
|
builder: (_) => const HomeView(), settings: settings);
|
||||||
|
|
||||||
// Default route, if no route this will show
|
case Routes.profileRoute:
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const ProfileView(), settings: settings);
|
||||||
|
|
||||||
|
case Routes.sceneRoute:
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const SceneView(), settings: settings);
|
||||||
|
|
||||||
|
case Routes.smartRoute:
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const SmartView(), settings: settings);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => Scaffold(
|
builder: (_) => Scaffold(
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
class RouteConstants {
|
class Routes {
|
||||||
static const String homeRoute = "/";
|
static const String splash = '/';
|
||||||
// static const String splash = '/';
|
static const String homeRoute = '/home';
|
||||||
|
static const String sceneRoute = '/scene';
|
||||||
|
static const String smartRoute = '/smart';
|
||||||
|
static const String profileRoute = '/profile';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user