Skip to content

Commit

Permalink
Merge pull request #4 from EsinShadrach/dev
Browse files Browse the repository at this point in the history
Added top Snackbar
  • Loading branch information
EsinShadrach committed May 13, 2024
2 parents 7e2aaed + f278890 commit 74114c7
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 20 deletions.
15 changes: 7 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "package:flutter_playground/providers/color_provider.dart";
import "package:flutter_playground/routes.dart";
import "package:flutter_playground/screens/change_color_scheme.dart";
import "package:provider/provider.dart";
import 'package:lucide_icons/lucide_icons.dart';

void main() {
runApp(
Expand All @@ -30,13 +29,13 @@ class MyApp extends StatelessWidget {
title: "Flutter Demo",
routes: routes(),
debugShowCheckedModeBanner: false,
builder: (context, child) {
return Scaffold(
body: SafeArea(
child: child!,
),
);
},
// builder: (context, child) {
// return Scaffold(
// body: SafeArea(
// child: child!,
// ),
// );
// },
onUnknownRoute: (settings) {
return MaterialPageRoute(
builder: (context) => const Scaffold(
Expand Down
3 changes: 3 additions & 0 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "package:flutter_playground/screens/examples/hero_widget/hero_widget_exam
import "package:flutter_playground/screens/examples/overlay_example/overlay_example_screen.dart";
import "package:flutter_playground/screens/examples/scale_down_btn/scale_down_btn_example.dart";
import "package:flutter_playground/screens/page_animation/page_animation.dart";
import "package:flutter_playground/screens/top_snackbar/top_snackbar.dart";

mixin AppRoutes {
static const String home = "/";
Expand All @@ -13,6 +14,7 @@ mixin AppRoutes {
static const String scaleDownOnPressed = "/scale-down-on-pressed-btn";
static const String overlayExample = "/overlay-example";
static const String heroWidget = "/hero-widget";
static const String topSnackbar = "/top-snackbar";
}

Map<String, WidgetBuilder> routes() => {
Expand All @@ -22,4 +24,5 @@ Map<String, WidgetBuilder> routes() => {
AppRoutes.scaleDownOnPressed: (context) => const ScaleDownButton(),
AppRoutes.overlayExample: (context) => const OverlayScreenExample(),
AppRoutes.heroWidget: (context) => const HeroWidgetScreen(),
AppRoutes.topSnackbar: (context) => const TopSnackbar(),
};
31 changes: 19 additions & 12 deletions lib/screens/examples/hero_widget/hero_widget_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class HeroWidgetScreen extends StatelessWidget {
appBar: AppBar(
title: const Text("Hero Screen - 1"),
),
body: Center(
body: Align(
alignment: Alignment.bottomRight,
child: Container(
clipBehavior: Clip.hardEdge,
margin: const EdgeInsets.all(10),
Expand All @@ -30,6 +31,7 @@ class HeroWidgetScreen extends StatelessWidget {
},
child: Hero(
tag: "peick",
transitionOnUserGestures: true,
flightShuttleBuilder: (flightContext, animation, flightDirection,
fromHeroContext, toHeroContext) {
final customAnimation = Tween<double>(
Expand All @@ -45,8 +47,17 @@ class HeroWidgetScreen extends StatelessWidget {
..setEntry(3, 2, 0.003)
..rotateX(customAnimation.value * pi),
alignment: Alignment.center,
child: Image.asset(
"assets/peick.webp",
child: Container(
clipBehavior: Clip.hardEdge,
margin: const EdgeInsets.all(10),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Image.asset(
"assets/peick.webp",
),
),
);
},
Expand Down Expand Up @@ -80,15 +91,11 @@ class SecondScreen extends StatelessWidget {
borderRadius: BorderRadius.circular(10),
),
),
child: InkWell(
onTap: () {
//
},
child: Hero(
tag: "peick",
child: Image.asset(
"assets/peick.webp",
),
child: Hero(
tag: "peick",
transitionOnUserGestures: true,
child: Image.asset(
"assets/peick.webp",
),
),
),
Expand Down
141 changes: 141 additions & 0 deletions lib/screens/top_snackbar/top_snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import "package:flutter/material.dart";
import "package:flutter_playground/extensions.dart";

class TopSnackbar extends StatelessWidget {
const TopSnackbar({super.key});
static OverlayEntry? overlayEntry;

void showOverlay(BuildContext context) {
final overlayState = Overlay.of(context);
if (overlayEntry == null) {
overlayEntry = OverlayEntry(
builder: (context) {
return CustomSnackbar(
tapFn: () {
overlayEntry?.remove();
overlayEntry = null;
},
);
},
);
overlayState.insert(overlayEntry!);
} else {
overlayEntry?.remove();
overlayEntry = null;
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Title"),
),
body: Container(
alignment: Alignment.center,
child: FilledButton(
onPressed: () {
showOverlay(context);
},
child: const Text("Show Me"),
),
),
);
}
}

class CustomSnackbar extends StatefulWidget {
const CustomSnackbar({
super.key,
required this.tapFn,
});
final Function() tapFn;

@override
State<CustomSnackbar> createState() => _CustomSnackbarState();
}

class _CustomSnackbarState extends State<CustomSnackbar>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
late final Animation<Offset> _animation;

@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: Durations.short4,
debugLabel: "topsnackbar",
);

_animation = Tween<Offset>(
begin: const Offset(0, -1),
end: const Offset(0, 0),
).animate(
CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
),
);
_controller.forward();
super.initState();
}

@override
Widget build(BuildContext context) {
return Positioned(
top: 0,
left: 0,
right: 0,
child: Material(
type: MaterialType.transparency,
child: ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 200,
),
child: SlideTransition(
position: _animation,
child: Container(
decoration: BoxDecoration(
color: context.colorScheme.surfaceVariant,
),
padding: const EdgeInsets.all(10),
child: SafeArea(
bottom: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Hey Nigger",
style: context.textTheme.titleMedium,
),
const Spacer(),
Text(
"lorem ipsum is a simple dummy text of the printing and type setting industry",
style: context.textTheme.bodyMedium,
),
Align(
alignment: Alignment.bottomRight,
child: TextButton(
style: TextButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
onPressed: () {
_controller.reverse().then((_) {
widget.tapFn();
});
},
child: const Text("Close"),
),
)
],
),
),
),
),
),
),
);
}
}

0 comments on commit 74114c7

Please sign in to comment.