Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions lib/components/app_animated_switcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import 'package:shop/constants.dart';

/// Generic AnimatedSwitcher wrapper used to keep page transitions consistent.
class AppAnimatedSwitcher extends StatelessWidget {
const AppAnimatedSwitcher({
super.key,
required this.child,
this.duration = defaultDuration,
this.switchInCurve = Curves.easeOut,
this.switchOutCurve = Curves.easeIn,
this.offset = const Offset(0, 0.04),
});

final Widget child;
final Duration duration;
final Curve switchInCurve;
final Curve switchOutCurve;
final Offset offset;

@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
duration: duration,
switchInCurve: switchInCurve,
switchOutCurve: switchOutCurve,
transitionBuilder: (child, animation) {
final offsetAnimation =
Tween<Offset>(begin: offset, end: Offset.zero).animate(animation);

return FadeTransition(
opacity: animation,
child: SlideTransition(
position: offsetAnimation,
child: child,
),
);
},
child: child,
);
}
}
20 changes: 2 additions & 18 deletions lib/entry_point.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:shop/components/app_animated_switcher.dart';
import 'package:shop/constants.dart';
import 'package:shop/route/screen_export.dart';

Expand Down Expand Up @@ -75,24 +76,7 @@ class _EntryPointState extends State<EntryPoint> {
),
],
),
// body: _pages[_currentIndex],
body: AnimatedSwitcher(
duration: defaultDuration,
switchInCurve: Curves.easeOut,
switchOutCurve: Curves.easeIn,
transitionBuilder: (child, animation) {
final offsetAnimation = Tween<Offset>(
begin: const Offset(0, 0.04),
end: Offset.zero,
).animate(animation);
return FadeTransition(
opacity: animation,
child: SlideTransition(
position: offsetAnimation,
child: child,
),
);
},
body: AppAnimatedSwitcher(
child: KeyedSubtree(
key: ValueKey<int>(_currentIndex),
child: _pages[_currentIndex],
Expand Down
20 changes: 2 additions & 18 deletions lib/screens/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shop/components/app_animated_switcher.dart';
import 'package:shop/constants.dart';
import 'package:shop/providers/cart_provider.dart';
import 'package:shop/screens/category/views/categories_list_screen.dart';
Expand Down Expand Up @@ -27,24 +28,7 @@ class _MainScreenState extends State<MainScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: AnimatedSwitcher(
duration: defaultDuration,
switchInCurve: Curves.easeOut,
switchOutCurve: Curves.easeIn,
transitionBuilder: (child, animation) {
final offsetAnimation = Tween<Offset>(
begin: const Offset(0, 0.04),
end: Offset.zero,
).animate(animation);

return FadeTransition(
opacity: animation,
child: SlideTransition(
position: offsetAnimation,
child: child,
),
);
},
body: AppAnimatedSwitcher(
child: KeyedSubtree(
key: ValueKey<int>(_selectedIndex),
child: _screens[_selectedIndex],
Expand Down
Loading