mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 07:04:54 +00:00
Implemented Navigation to these screens:
- Home - Scene - Smart - profile Converted to state based Provider
This commit is contained in:
48
lib/features/home/home_provider.dart
Normal file
48
lib/features/home/home_provider.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/profile/profile_view.dart';
|
||||
import 'package:syncrow_app/features/scene/scene_view.dart';
|
||||
import 'package:syncrow_app/features/smart/smart_view.dart';
|
||||
|
||||
import 'home_state.dart';
|
||||
import 'widgets/home_view_body.dart';
|
||||
|
||||
class HomeProvider extends ChangeNotifier {
|
||||
final state = HomeState();
|
||||
|
||||
static int pageIndex = 0;
|
||||
|
||||
var bottomNavItems = [
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
label: 'Home',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.check_box_outlined),
|
||||
label: 'Scene',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.view_in_ar),
|
||||
label: 'Smart',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.account_circle),
|
||||
label: 'Profile',
|
||||
),
|
||||
];
|
||||
|
||||
final List<Widget> pages = [
|
||||
const HomeViewBody(),
|
||||
const ScenePage(),
|
||||
const SmartPage(),
|
||||
const ProfilePage(),
|
||||
];
|
||||
|
||||
Widget currentPage() {
|
||||
return pages[pageIndex];
|
||||
}
|
||||
|
||||
void updatePageIndex(int index, BuildContext context) {
|
||||
pageIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
5
lib/features/home/home_state.dart
Normal file
5
lib/features/home/home_state.dart
Normal file
@ -0,0 +1,5 @@
|
||||
class HomeState {
|
||||
HomeState() {
|
||||
// init some variables
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package: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 {
|
||||
const HomeView({super.key});
|
||||
import '../shared_widgets/default_nav_bar.dart';
|
||||
import 'home_provider.dart';
|
||||
import 'widgets/default_app_bar.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -16,9 +16,7 @@ class HomeView extends StatelessWidget {
|
||||
builder: (context, provider, child) {
|
||||
return Scaffold(
|
||||
appBar: const DefaultAppBar(),
|
||||
body: provider.pageIndex == 0
|
||||
? const HomeViewBody()
|
||||
: provider.currentPage,
|
||||
body: provider.currentPage(),
|
||||
bottomNavigationBar: const DefaultNavBar(),
|
||||
);
|
||||
},
|
||||
@ -1,3 +0,0 @@
|
||||
class HomeModel {
|
||||
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
7
lib/features/profile/profile_provider.dart
Normal file
7
lib/features/profile/profile_provider.dart
Normal file
@ -0,0 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'profile_state.dart';
|
||||
|
||||
class ProfileProvider extends ChangeNotifier {
|
||||
final state = ProfileState();
|
||||
}
|
||||
6
lib/features/profile/profile_state.dart
Normal file
6
lib/features/profile/profile_state.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class ProfileState {
|
||||
|
||||
ProfileState() {
|
||||
// init some variables
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../provider/profile_provider.dart';
|
||||
import 'profile_provider.dart';
|
||||
|
||||
class ProfileView extends StatelessWidget {
|
||||
const ProfileView({super.key});
|
||||
class ProfilePage extends StatelessWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (BuildContext context) => ProfileProvider(),
|
||||
builder: (context, child) => const Center(
|
||||
child: Text('Profile'),
|
||||
child: Text('Profile Page'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ProfileProvider extends ChangeNotifier {}
|
||||
@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SceneProvider extends ChangeNotifier {
|
||||
import 'scene_state.dart';
|
||||
|
||||
class SceneProvider extends ChangeNotifier {
|
||||
final state = SceneState();
|
||||
}
|
||||
6
lib/features/scene/scene_state.dart
Normal file
6
lib/features/scene/scene_state.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class SceneState {
|
||||
|
||||
SceneState() {
|
||||
// init some variables
|
||||
}
|
||||
}
|
||||
18
lib/features/scene/scene_view.dart
Normal file
18
lib/features/scene/scene_view.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'scene_provider.dart';
|
||||
|
||||
class ScenePage extends StatelessWidget {
|
||||
const ScenePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (BuildContext context) => SceneProvider(),
|
||||
builder: (context, child) => const Center(
|
||||
child: Text('Scene Page'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SceneView extends StatelessWidget {
|
||||
const SceneView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
child: Text('Scene'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:syncrow_app/features/home/provider/provider.dart';
|
||||
|
||||
import '../home/home_provider.dart';
|
||||
|
||||
class DefaultNavBar extends StatelessWidget {
|
||||
const DefaultNavBar({
|
||||
@ -9,50 +10,21 @@ class DefaultNavBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (BuildContext context) => HomeProvider(),
|
||||
child: BottomNavigationBar(
|
||||
onTap: (int index) {
|
||||
context.read<HomeProvider>().updatePageIndex(index, context);
|
||||
return Consumer<HomeProvider>(
|
||||
builder: (context, provider, child) {
|
||||
return BottomNavigationBar(
|
||||
onTap: (int index) => provider.updatePageIndex(index, context),
|
||||
currentIndex: HomeProvider.pageIndex,
|
||||
selectedItemColor: Colors.black,
|
||||
unselectedItemColor: Colors.grey,
|
||||
elevation: 10,
|
||||
items: provider.bottomNavItems,
|
||||
);
|
||||
},
|
||||
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',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultBottomNavBarItem extends BottomNavigationBarItem {
|
||||
DefaultBottomNavBarItem({required super.icon});
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SmartProvider extends ChangeNotifier {}
|
||||
7
lib/features/smart/smart_provider.dart
Normal file
7
lib/features/smart/smart_provider.dart
Normal file
@ -0,0 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'smart_state.dart';
|
||||
|
||||
class SmartProvider extends ChangeNotifier {
|
||||
final state = SmartState();
|
||||
}
|
||||
6
lib/features/smart/smart_state.dart
Normal file
6
lib/features/smart/smart_state.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class SmartState {
|
||||
|
||||
SmartState() {
|
||||
// init some variables
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../provider/smart_provider.dart';
|
||||
import 'smart_provider.dart';
|
||||
|
||||
class SmartView extends StatelessWidget {
|
||||
const SmartView({super.key});
|
||||
class SmartPage extends StatelessWidget {
|
||||
const SmartPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (BuildContext context) => SmartProvider(),
|
||||
builder: (context, child) => const Center(
|
||||
child: Text('Smart'),
|
||||
child: Text('Smart Page'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
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';
|
||||
import 'package:syncrow_app/features/home/home_view.dart';
|
||||
import 'package:syncrow_app/features/profile/profile_view.dart';
|
||||
import 'package:syncrow_app/features/scene/scene_view.dart';
|
||||
import 'package:syncrow_app/features/smart/smart_view.dart';
|
||||
import 'package:syncrow_app/features/splash/splash_view.dart';
|
||||
|
||||
import 'routing_constants.dart';
|
||||
@ -16,19 +16,19 @@ class Router {
|
||||
|
||||
case Routes.homeRoute:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const HomeView(), settings: settings);
|
||||
builder: (_) => const HomePage(), settings: settings);
|
||||
|
||||
case Routes.profileRoute:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const ProfileView(), settings: settings);
|
||||
builder: (_) => const ProfilePage(), settings: settings);
|
||||
|
||||
case Routes.sceneRoute:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const SceneView(), settings: settings);
|
||||
builder: (_) => const ScenePage(), settings: settings);
|
||||
|
||||
case Routes.smartRoute:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const SmartView(), settings: settings);
|
||||
builder: (_) => const SmartPage(), settings: settings);
|
||||
|
||||
default:
|
||||
return MaterialPageRoute(
|
||||
|
||||
Reference in New Issue
Block a user