Skip to content

Commit

Permalink
add navigationbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmarmalade committed Sep 11, 2022
1 parent e2747ad commit 04a0c37
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 53 deletions.
154 changes: 102 additions & 52 deletions lib/pages/newhome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,133 @@ class NewHome extends StatelessWidget {
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => RoomsNotifier(),
child: const HomePageScaffold(),
child: const HomePageRouter(),
);
}
}

class HomePageScaffold extends StatefulWidget {
const HomePageScaffold({
Key? key,
}) : super(key: key);
class HomePageRouter extends StatefulWidget {
const HomePageRouter({Key? key}) : super(key: key);

@override
State<HomePageScaffold> createState() => _HomePageScaffoldState();
State<HomePageRouter> createState() => _HomePageRouterState();
}

class _HomePageScaffoldState extends State<HomePageScaffold> {
class _HomePageRouterState extends State<HomePageRouter> {
int _selectedIndex = 0;

@override
Widget build(BuildContext context) {
final counter = Provider.of<RoomsNotifier>(context);
TextEditingController controller = TextEditingController();
double screenWidth = MediaQuery.of(context).size.width;

return Scaffold(
appBar: AppBar(title: const Text("New Home Preview"), actions: [
IconButton(
onPressed: () {
counter.hideOfflineRooms();
},
tooltip: 'Hide Offline Rooms',
icon: const Icon(Icons.hide_source_rounded)),
]),
floatingActionButton:
HomePageAddButton(controller: controller, counter: counter),
body: HomePageGridView(screenWidth: screenWidth, roomNotifier: counter),
bottomNavigationBar: NavigationBar(
destinations: const [
NavigationDestination(
icon: Icon(Icons.star_rate_rounded),
label: 'Favorites',
),
NavigationDestination(
icon: Icon(Icons.list_alt_rounded),
label: 'Recommend',
),
NavigationDestination(
icon: Icon(Icons.settings_rounded),
label: 'Settings',
),
],
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
});
}),
body: [
Scaffold(
appBar: AppBar(title: const Text("Favorites"), actions: [
IconButton(
onPressed: () => counter.hideOfflineRooms(),
tooltip: 'Hide Offline Rooms',
icon: const Icon(Icons.remove_circle_outline_rounded))
]),
body:
HomePageGridView(screenWidth: screenWidth, roomNotifier: counter),
floatingActionButton:
HomePageAddButton(controller: controller, counter: counter),
),
Scaffold(
appBar: AppBar(title: const Text("Recommend")),
body: const Center(child: Text('recommend')) //RecommendPages(),
),
Scaffold(
appBar: AppBar(title: const Text("Settings")),
body: const Center(child: Text('Settings')) //RecommendPages(),
),
][_selectedIndex],
);
}
}

class HomePageGridView extends StatelessWidget {
const HomePageGridView({
Key? key,
required this.screenWidth,
required this.roomNotifier,
}) : super(key: key);
const HomePageGridView(
{Key? key, required this.screenWidth, required this.roomNotifier})
: super(key: key);

final double screenWidth;
final RoomsNotifier roomNotifier;

@override
Widget build(BuildContext context) {
return MasonryGridView.count(
crossAxisCount: screenWidth > 1280
? 4
: (screenWidth > 960 ? 3 : (screenWidth > 640 ? 2 : 1)),
itemCount: roomNotifier.singleRoomsList.length,
itemBuilder: (context, index) {
if (roomNotifier.singleRoomsList.isNotEmpty) {
SingleRoom room = roomNotifier.singleRoomsList[index];
return RoomCard(room: room, counter: roomNotifier, index: index);
} else {
return Column(
mainAxisSize: MainAxisSize.max,
children: const [
Align(
alignment: AlignmentDirectional(0, 0),
child: Icon(
Icons.post_add_outlined,
size: 64,
),
),
Expanded(
child: Text(
'Hello World',
),
),
],
);
}
},
if (roomNotifier.singleRoomsList.isNotEmpty) {
return MasonryGridView.count(
crossAxisCount: screenWidth > 1280
? 4
: (screenWidth > 960 ? 3 : (screenWidth > 640 ? 2 : 1)),
itemCount: roomNotifier.singleRoomsList.length,
itemBuilder: (context, index) {
SingleRoom room = roomNotifier.singleRoomsList[index];
return RoomCard(room: room, counter: roomNotifier, index: index);
});
} else {
return const HomeEmptyScreen();
}
}
}

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

@override
Widget build(BuildContext context) {
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Icon(
Icons.post_add_rounded,
size: 144,
color: Theme.of(context).disabledColor,
),
),
Expanded(
child: Text.rich(
TextSpan(children: [
TextSpan(
text: "No data! 没有数据\n\n",
style: Theme.of(context).textTheme.headlineLarge),
TextSpan(
text: "Click the button below\nto add your first link",
style: Theme.of(context).textTheme.headline3),
]),
textAlign: TextAlign.center),
),
],
),
);
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/pages/recommendpages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

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

@override
Widget build(BuildContext context) {
return const Text('recommend');
}
}
22 changes: 21 additions & 1 deletion lib/utils/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ class MyTheme {
fontWeight: FontWeight.bold,
color: Colors.indigo,
),
headlineLarge: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.indigo,
),
headline3: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.blueGrey,
),
));

ThemeData darkThemeData = ThemeData.from(
colorScheme: const ColorScheme.dark(
primary: Colors.indigo,
secondary: Colors.indigo,
secondary: Colors.indigoAccent,
brightness: Brightness.dark,
),
useMaterial3: true,
Expand All @@ -35,5 +45,15 @@ class MyTheme {
fontWeight: FontWeight.bold,
color: Colors.indigo,
),
headline3: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
),
headlineLarge: TextStyle(
fontSize: 32,
fontWeight: FontWeight.w500,
color: Colors.indigo,
),
));
}

0 comments on commit 04a0c37

Please sign in to comment.