♻️ code refactor
parent
e984f7eba5
commit
bc279be86f
@ -1,4 +1,4 @@
|
||||
library flutter_slider_drawer;
|
||||
|
||||
export 'package:flutter_slider_drawer/src/slider_open.dart';
|
||||
export 'package:flutter_slider_drawer/src/slider_direction.dart';
|
||||
export 'package:flutter_slider_drawer/src/slider.dart';
|
||||
|
@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slider_drawer/src/slider_direction.dart';
|
||||
|
||||
class SliderAppBar extends StatelessWidget {
|
||||
final EdgeInsets appBarPadding;
|
||||
final Color appBarColor;
|
||||
final Widget drawerIcon;
|
||||
final Color splashColor;
|
||||
final Color drawerIconColor;
|
||||
final double drawerIconSize;
|
||||
final double appBarHeight;
|
||||
final AnimationController animationController;
|
||||
final VoidCallback onTap;
|
||||
final Widget title;
|
||||
final bool isTitleCenter;
|
||||
final Widget trailing;
|
||||
final SlideDirection slideDirection;
|
||||
|
||||
const SliderAppBar(
|
||||
{Key key,
|
||||
this.appBarPadding,
|
||||
this.appBarColor,
|
||||
this.drawerIcon,
|
||||
this.splashColor,
|
||||
this.drawerIconColor,
|
||||
this.drawerIconSize,
|
||||
this.animationController,
|
||||
this.onTap,
|
||||
this.title,
|
||||
this.isTitleCenter,
|
||||
this.trailing,
|
||||
this.slideDirection, this.appBarHeight})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: appBarHeight,
|
||||
padding: appBarPadding ?? const EdgeInsets.only(top: 24),
|
||||
color: appBarColor,
|
||||
child: Row(
|
||||
children: appBar(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> appBar() {
|
||||
List<Widget> list = [
|
||||
drawerIcon ??
|
||||
IconButton(
|
||||
splashColor: splashColor ?? Colors.black,
|
||||
icon: AnimatedIcon(
|
||||
icon: AnimatedIcons.menu_close,
|
||||
color: drawerIconColor,
|
||||
size: drawerIconSize,
|
||||
progress: animationController),
|
||||
onPressed: () => onTap()),
|
||||
Expanded(
|
||||
child: isTitleCenter
|
||||
? Center(
|
||||
child: title,
|
||||
)
|
||||
: title,
|
||||
),
|
||||
trailing ??
|
||||
SizedBox(
|
||||
width: 35,
|
||||
)
|
||||
];
|
||||
|
||||
if (slideDirection == SlideDirection.RIGHT_TO_LEFT) {
|
||||
return list.reversed.toList();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_slider_drawer/flutter_slider_drawer.dart';
|
||||
|
||||
class Utils {
|
||||
///
|
||||
/// This method get Offset base on [sliderOpen] type
|
||||
///
|
||||
|
||||
static Offset getOffsetValues(SlideDirection direction, double value) {
|
||||
switch (direction) {
|
||||
case SlideDirection.LEFT_TO_RIGHT:
|
||||
return Offset(value, 0);
|
||||
case SlideDirection.RIGHT_TO_LEFT:
|
||||
return Offset(-value, 0);
|
||||
case SlideDirection.TOP_TO_BOTTOM:
|
||||
return Offset(0, value);
|
||||
default:
|
||||
return Offset(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Offset getOffsetValueForShadow(
|
||||
SlideDirection direction, double value, double slideOpenWidth) {
|
||||
switch (direction) {
|
||||
case SlideDirection.LEFT_TO_RIGHT:
|
||||
return Offset(value - (slideOpenWidth > 50 ? 20 : 10), 0);
|
||||
case SlideDirection.RIGHT_TO_LEFT:
|
||||
return Offset(-value - 5, 0);
|
||||
case SlideDirection.TOP_TO_BOTTOM:
|
||||
return Offset(0, value - (slideOpenWidth > 50 ? 15 : 5));
|
||||
default:
|
||||
return Offset(value - 30.0, 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slider_drawer/src/slider_direction.dart';
|
||||
|
||||
///
|
||||
/// Build and Align the Menu widget based on the slide open type
|
||||
///
|
||||
class SlideMenuBar extends StatelessWidget {
|
||||
final SlideDirection slideDirection;
|
||||
final double sliderMenuOpenSize;
|
||||
final Widget sliderMenu;
|
||||
|
||||
const SlideMenuBar(
|
||||
{Key key, this.slideDirection, this.sliderMenuOpenSize, this.sliderMenu})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var container = Container(
|
||||
width: sliderMenuOpenSize,
|
||||
child: sliderMenu,
|
||||
);
|
||||
switch (slideDirection) {
|
||||
case SlideDirection.LEFT_TO_RIGHT:
|
||||
return container;
|
||||
break;
|
||||
case SlideDirection.RIGHT_TO_LEFT:
|
||||
return Positioned(right: 0, top: 0, bottom: 0, child: container);
|
||||
case SlideDirection.TOP_TO_BOTTOM:
|
||||
return Positioned(right: 0, left: 0, top: 0, child: container);
|
||||
break;
|
||||
}
|
||||
return Container();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue