Skip to content

Commit

Permalink
Merge pull request #18 from guchengxi1994/layout
Browse files Browse the repository at this point in the history
Layout
  • Loading branch information
guchengxi1994 authored Apr 26, 2024
2 parents ec5a6a3 + 7cb072d commit 83f89e4
Show file tree
Hide file tree
Showing 20 changed files with 451 additions and 91 deletions.
3 changes: 3 additions & 0 deletions assets/icons/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/idashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/itoolbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/toolbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 15 additions & 12 deletions lib/app/linux.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:all_in_one/app/common.dart';
import 'package:all_in_one/layout/layout.dart';
import 'package:all_in_one/routers/routers.dart';
import 'package:all_in_one/schedule/cron_listener.dart';
import 'package:all_in_one/software_monitor/notifier/monitor_item_notifier.dart';
Expand Down Expand Up @@ -29,7 +30,7 @@ void runLinuxAPP() async {

runApp(ProviderScope(
// observers: kDebugMode ? [SimpleObserver()] : [],
child: _Lauout(
child: _Wrapper(
child: MaterialApp(
scrollBehavior: AppScrollBehavior(),
theme: ThemeData(
Expand All @@ -39,23 +40,21 @@ void runLinuxAPP() async {
tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
),
debugShowCheckedModeBanner: false,
routes: Routers.routers,
navigatorKey: Routers.navigatorKey,
initialRoute: Routers.workboardScreen,
home: const Layout(),
),
),
));
}

class _Lauout extends ConsumerStatefulWidget {
const _Lauout({required this.child});
class _Wrapper extends ConsumerStatefulWidget {
const _Wrapper({required this.child});
final Widget child;

@override
ConsumerState<_Lauout> createState() => __LauoutState();
ConsumerState<_Wrapper> createState() => __WrapperState();
}

class __LauoutState extends ConsumerState<_Lauout> {
class __WrapperState extends ConsumerState<_Wrapper> {
initStream() {
scheduleStream.listen((event) {
logger.info("events $event");
Expand Down Expand Up @@ -105,13 +104,17 @@ class __LauoutState extends ConsumerState<_Lauout> {
brightness: Brightness.dark,
title: Row(
children: [
if (ref.watch(routersProvider) != Routers.workboardScreen)
if (ref.watch(toolEntryRoutersProvider) !=
Routers.workboardScreen)
InkWell(
onTap: () {
if (ref.watch(routersProvider) == Routers.entryScreen) {
ref.read(routersProvider.notifier).toMain();
if (ref.watch(toolEntryRoutersProvider) ==
Routers.entryScreen) {
ref.read(toolEntryRoutersProvider.notifier).toMain();
} else {
ref.read(routersProvider.notifier).toEntries();
ref
.read(toolEntryRoutersProvider.notifier)
.toEntries();
}
},
child: const Icon(Bootstrap.arrow_left),
Expand Down
43 changes: 18 additions & 25 deletions lib/app/windows.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:io';

import 'package:all_in_one/app/common.dart';
import 'package:all_in_one/routers/routers.dart';
import 'package:all_in_one/layout/layout.dart';
import 'package:all_in_one/schedule/cron_listener.dart';
import 'package:all_in_one/software_monitor/notifier/monitor_item_notifier.dart';
import 'package:all_in_one/common/logger.dart';
import 'package:all_in_one/styles/app_style.dart';
import 'package:flutter/material.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:window_manager/window_manager.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:all_in_one/src/rust/api/software_monitor_api.dart' as smapi;
Expand All @@ -29,7 +28,7 @@ void runWindowsAPP() async {

runApp(ProviderScope(
// observers: kDebugMode ? [SimpleObserver()] : [],
child: _Lauout(
child: _Wrapper(
child: MaterialApp(
scrollBehavior: AppScrollBehavior(),
theme: ThemeData(
Expand All @@ -39,23 +38,22 @@ void runWindowsAPP() async {
tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
),
debugShowCheckedModeBanner: false,
routes: Routers.routers,
navigatorKey: Routers.navigatorKey,
initialRoute: Routers.workboardScreen,
// initialRoute: Routers.workboardScreen,
home: const Layout(),
),
),
));
}

class _Lauout extends ConsumerStatefulWidget {
const _Lauout({required this.child});
class _Wrapper extends ConsumerStatefulWidget {
const _Wrapper({required this.child});
final Widget child;

@override
ConsumerState<_Lauout> createState() => __LauoutState();
ConsumerState<_Wrapper> createState() => __WrapperState();
}

class __LauoutState extends ConsumerState<_Lauout> {
class __WrapperState extends ConsumerState<_Wrapper> {
initStream() {
scheduleStream.listen((event) {
logger.info("events $event");
Expand Down Expand Up @@ -99,25 +97,20 @@ class __LauoutState extends ConsumerState<_Lauout> {
return Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
backgroundColor: AppStyle.appColor,
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(30),
preferredSize: const Size.fromHeight(50),
child: WindowCaption(
backgroundColor: AppStyle.appColor,
brightness: Brightness.dark,
backgroundColor: Colors.white,
brightness: Brightness.light,
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (ref.watch(routersProvider) != Routers.workboardScreen)
InkWell(
onTap: () {
if (ref.watch(routersProvider) == Routers.entryScreen) {
ref.read(routersProvider.notifier).toMain();
} else {
ref.read(routersProvider.notifier).toEntries();
}
},
child: const Icon(Bootstrap.arrow_left),
)
SizedBox(
width: 40,
height: 40,
child: Image.asset("assets/icon.png"),
),
],
),
),
Expand Down
102 changes: 102 additions & 0 deletions lib/layout/components/animated_sidebar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import 'package:all_in_one/layout/components/sidebar_item.dart';
import 'package:all_in_one/layout/notifiers/sidebar_notifier.dart';
import 'package:all_in_one/layout/styles.dart';
import 'package:all_in_one/styles/app_style.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class AnimatedSidebar extends ConsumerStatefulWidget {
const AnimatedSidebar({super.key, required this.outerController});
final AnimationController outerController;

@override
ConsumerState<AnimatedSidebar> createState() => _AnimatedSidebarState();
}

class _AnimatedSidebarState extends ConsumerState<AnimatedSidebar>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: Duration(milliseconds: LayoutStyle.duration),
vsync: this,
);
late final Animation<double> _animation = Tween<double>(
begin: LayoutStyle.sidebarCollapse, end: LayoutStyle.sidebarExpand)
.animate(_controller);

late double width = _animation.value;

@override
void initState() {
super.initState();
_controller.addListener(() {
setState(() {
width = _animation.value;
});
if (width == LayoutStyle.sidebarExpand) {
ref.read(sidebarProvider.notifier).changeStatus(true);
}

if (width == LayoutStyle.sidebarCollapse) {
ref.read(sidebarProvider.notifier).changeStatus(false);
}
});
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return SizedBox(
width: _animation.value,
child: MouseRegion(
onEnter: (event) {
_controller.forward();
widget.outerController.forward();
},
onExit: (event) {
_controller.reverse();
widget.outerController.reverse();
},
child: SizeTransition(
sizeFactor: _animation,
axis: Axis.horizontal,
child: Container(
height: double.infinity,
width: _animation.value,
// color: Colors.red,
decoration: const BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(
color: AppStyle.black,
offset: Offset(0, 4),
blurRadius: 10,
spreadRadius: 3,
)
]),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SidebarItemWidget(
item: SidebarItem(
icon: "assets/icons/dashboard.png",
index: 0,
name: "Dashboard",
inActiveIcon: "assets/icons/idashboard.png")),
SidebarItemWidget(
item: SidebarItem(
icon: "assets/icons/toolbox.png",
index: 1,
name: "Toolbox",
inActiveIcon: "assets/icons/itoolbox.png"))
],
),
),
),
),
);
}
}
72 changes: 72 additions & 0 deletions lib/layout/components/sidebar_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:all_in_one/layout/notifiers/page_notifier.dart';
import 'package:all_in_one/layout/notifiers/sidebar_notifier.dart';
import 'package:all_in_one/layout/styles.dart';
import 'package:all_in_one/styles/app_style.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class SidebarItem {
final String icon;
final String inActiveIcon;
final String name;
final int index;

SidebarItem(
{required this.icon,
required this.index,
required this.name,
required this.inActiveIcon});
}

class SidebarItemWidget extends ConsumerWidget {
const SidebarItemWidget({super.key, required this.item});
final SidebarItem item;

@override
Widget build(BuildContext context, WidgetRef ref) {
final isExpanded = ref.watch(sidebarProvider);
final isSelected = ref.watch(pageProvider) == item.index;
return GestureDetector(
onTap: () {
ref.read(pageProvider.notifier).changePage(item.index);
},
child: Container(
// alignment: Alignment.centerLeft,
width: isExpanded
? LayoutStyle.sidebarExpand
: LayoutStyle.sidebarCollapse,
padding: const EdgeInsets.all(10),
child: isExpanded
? Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
width: 30,
child: Image.asset(
isSelected ? item.icon : item.inActiveIcon,
),
),
const SizedBox(
width: 10,
),
AutoSizeText(
item.name,
style: TextStyle(
color: isSelected ? Colors.black : Colors.grey),
)
],
)
: SizedBox(
width: 30,
height: 30,
child: Image.asset(
isSelected ? item.icon : item.inActiveIcon,
),
),
),
);
}
}
Loading

0 comments on commit 83f89e4

Please sign in to comment.