-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from guchengxi1994/layout
Layout
- Loading branch information
Showing
20 changed files
with
451 additions
and
91 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.