Skip to content

Commit

Permalink
add ability to switch back to material theme
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Jan 2, 2024
1 parent 0157cd6 commit fc01e55
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 63 deletions.
11 changes: 5 additions & 6 deletions lib/base_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
WidgetsBinding.instance.addPostFrameCallback((_) {
NavbarNotifier.showSnackBar(context, message,
actionLabel: action,
bottom: 50,
bottom: kNavbarHeight * 1.2,
onActionPressed: onActionPressed,
duration: persist ? Duration(days: 1) : Duration(seconds: 3), onClosed: () {
if (mounted) {
Expand Down Expand Up @@ -197,7 +197,7 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
final icon = Icon(Icons.add, color: colorScheme.onPrimaryContainer, size: 28);
if (appController.showFAB || (appController.index < 2 && user!.isLoggedIn)) {
return Padding(
padding: (kM3NavbarHeight).bottomPadding,
padding: (kNavbarHeight * 1.2).bottomPadding,
child: FloatingActionButton.extended(
backgroundColor: colorScheme.primaryContainer,
heroTag: "addword${DateTime.now().millisecondsSinceEpoch}",
Expand Down Expand Up @@ -250,9 +250,8 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
exploreController.scrollToIndex = 0;
},
onChanged: (x) async {
ref
.read(appProvider.notifier)
.copyWith(appController.copyWith(index: x, showFAB: x < 2, extended: true));
ref.read(appProvider.notifier).copyWith(appController.copyWith(
index: x, showFAB: x < 2 && user!.isLoggedIn, extended: true));

/// Simulate DragGesture on pageView
final pageController = exploreController.pageController;
Expand All @@ -269,7 +268,7 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
}
},
decoration: FloatingNavbarDecoration(
height: 80,
height: kNavbarHeight * 1.2,
backgroundColor: SizeUtils.isDesktop
? colorScheme.surfaceVariant
: colorScheme.scrim.withOpacity(0.2),
Expand Down
3 changes: 1 addition & 2 deletions lib/constants/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ class Constants {
static const String timeFormatter = 'hh:mm a';
static const int ratingAskInterval = 7;
static const int scrollMessageShownInterval = 7;
static const Duration timeoutDuration = Duration(seconds: 10);
static const Duration timeoutDuration = Duration(seconds: 20);

static const String LAUNCHER_ICON = '@mipmap/launcher_icon';


/// Features
static const String draftsFeature = 'drafts_feature';
Expand Down
2 changes: 1 addition & 1 deletion lib/navbar/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class DashboardMobile extends ConsumerWidget {
final user = ref.watch(userNotifierProvider);
final word = dashboardController.wordOfTheDay;
return Padding(
padding: 80.0.bottomPadding,
padding: (kNavbarHeight * 1.2).bottomPadding,
child: CustomScrollView(
scrollBehavior: const MaterialScrollBehavior().copyWith(overscroll: true),
physics: BouncingScrollPhysics(
Expand Down
2 changes: 1 addition & 1 deletion lib/navbar/explore/explore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class _ExploreWordsMobileState extends ConsumerState<ExploreWordsMobile>
animation: _progressAnimationController,
builder: (context, child) {
return Padding(
padding: 80.0.bottomPadding + 24.0.topPadding,
padding: (kNavbarHeight * 1.2).bottomPadding + 24.0.topPadding,
child: settingsController.autoScroll.enabled
? LinearProgressIndicator(
value: _progressAnimationController.value,
Expand Down
66 changes: 45 additions & 21 deletions lib/navbar/profile/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _SettingsPageMobileState extends ConsumerState<SettingsPageMobile> {
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final user = ref.watch(userNotifierProvider);
final appTheme = ref.read(appThemeProvider);
final appTheme = ref.watch(appThemeProvider);
ref.listen<UserModel>(userNotifierProvider, (UserModel? userOld, UserModel? userNew) {
if (userNew != null) {
user.setUser(userNew);
Expand All @@ -118,7 +118,7 @@ class _SettingsPageMobileState extends ConsumerState<SettingsPageMobile> {
padding: 16.0.horizontalPadding,
child: Row(
children: [
Text('Theme',
Text('${appTheme.isDark ? 'Dark' : 'Light'} Theme',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
Expand All @@ -129,28 +129,52 @@ class _SettingsPageMobileState extends ConsumerState<SettingsPageMobile> {
color: colorScheme.primary,
),
10.0.hSpacer(),
AnimatedBuilder(
animation: settingsController,
builder: (context, child) {
return VocabSwitch(
value: appTheme.isDark,
onChanged: (x) {
ref.read(appThemeProvider.notifier).setDark(x);
widget.onThemeChanged(x ? ThemeMode.dark : ThemeMode.light);
});
}),
VocabSwitch(
value: appTheme.isDark,
onChanged: (x) {
ref.read(appThemeProvider.notifier).setDark(x);
// widget.onThemeChanged(x ? ThemeMode.dark : ThemeMode.light);
})
],
),
),
AnimatedBuilder(
animation: settingsController,
builder: (context, child) {
return ThemeSelector(
value: appTheme.themeSeed,
onThemeChanged: (val) {
ref.read(appThemeProvider.notifier).setThemeSeed(val);
widget.onThemeChanged(val);
});
Padding(
padding: 16.0.horizontalPadding,
child: Row(
children: [
Text('Use Classic Theme',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
)),
Spacer(),
VocabSwitch(
value: appTheme.isClassic,
onChanged: (x) {
ref.read(appThemeProvider.notifier).setClassic(x);
widget.onThemeChanged(x);
})
],
),
),
Padding(
padding: 16.0.horizontalPadding,
child: Row(
children: [
Text('Choose color scheme',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
)),
Spacer(),
],
),
),
ThemeSelector(
value: appTheme.themeSeed,
onThemeChanged: (val) {
ref.read(appThemeProvider.notifier).setThemeSeed(val);
widget.onThemeChanged(val);
}),
20.0.vSpacer(),
hLine(),
Expand Down
5 changes: 2 additions & 3 deletions lib/navbar/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ class _MobileViewState extends ConsumerState<MobileView> {
}
final List<List<Word>> wordsByAlphabet = resp.data as List<List<Word>>;
return Padding(
padding: 8.0.horizontalPadding + 50.0.bottomPadding,
padding: 8.0.horizontalPadding + (kNavbarHeight * 1.2).bottomPadding,
child: GridView.custom(
controller: _scrollController,
padding: 80.0.bottomPadding,
gridDelegate: SliverQuiltedGridDelegate(
crossAxisCount: 4,
mainAxisSpacing: 8,
Expand Down Expand Up @@ -472,7 +471,7 @@ class _SearchViewPageState extends State<SearchViewPage> {
),
Expanded(
child: ListView.builder(
padding: kBottomNavigationBarHeight.bottomPadding,
padding: (kNavbarHeight * 1.2).bottomPadding,
itemBuilder: (context, index) {
return Container(
margin: 8.0.horizontalPadding + 4.0.verticalPadding,
Expand Down
67 changes: 38 additions & 29 deletions lib/widgets/responsive.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocabhub/main.dart';
import 'package:vocabhub/utils/size_utils.dart';

class ResponsiveBuilder extends StatefulWidget {
class ResponsiveBuilder extends ConsumerStatefulWidget {
final WidgetBuilder desktopBuilder;
final WidgetBuilder mobileBuilder;
final bool animate;
Expand All @@ -24,10 +26,11 @@ class ResponsiveBuilder extends StatefulWidget {
: super(key: key);

@override
State<ResponsiveBuilder> createState() => _ResponsiveBuilderState();
ConsumerState<ConsumerStatefulWidget> createState() => _ResponsiveBuilderState();
}

class _ResponsiveBuilderState extends State<ResponsiveBuilder> with TickerProviderStateMixin {
class _ResponsiveBuilderState extends ConsumerState<ResponsiveBuilder>
with TickerProviderStateMixin {
@override
void initState() {
super.initState();
Expand All @@ -37,18 +40,21 @@ class _ResponsiveBuilderState extends State<ResponsiveBuilder> with TickerProvid
} else {
_animation = AlwaysStoppedAnimation(widget.initialAnimationValue);
}
if (widget.repeatAnimation) {
_controller.repeat(reverse: true);
} else {
_animation = Tween<double>(begin: 0, end: 1).animate(_controller);
_controller.forward();
_controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
widget.onAnimateComplete?.call();
_controller.stop();
// _controller.reset();
}
});
final apptheme = ref.read(appThemeProvider);
if (!apptheme.isClassic) {
if (widget.repeatAnimation) {
_controller.repeat(reverse: true);
} else {
_animation = Tween<double>(begin: 0, end: 1).animate(_controller);
_controller.forward();
_controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
widget.onAnimateComplete?.call();
_controller.stop();
// _controller.reset();
}
});
}
}
}

Expand All @@ -65,9 +71,9 @@ class _ResponsiveBuilderState extends State<ResponsiveBuilder> with TickerProvid

@override
void didUpdateWidget(covariant ResponsiveBuilder oldWidget) {
print('didUpdateWidget');
if (oldWidget.animate != widget.animate) {
_animation = Tween<double>(begin: 0, end: 1).animate(_controller);

if (widget.animate) {
if (widget.repeatAnimation) {
_controller.repeat(reverse: true);
Expand Down Expand Up @@ -109,21 +115,24 @@ class _ResponsiveBuilderState extends State<ResponsiveBuilder> with TickerProvid
if (!SizeUtils.isMobile) {
return widget.desktopBuilder(context);
}
final appTheme = ref.watch(appThemeProvider);
return Stack(
children: [
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return CustomPaint(
painter: BackgroundPainter(
primaryColor: colorScheme.primary,
secondaryColor: colorScheme.inversePrimary,
animation: _animation,
),
child: Container(),
);
}),
BackdropFilter(filter: ImageFilter.blur(sigmaX: 60, sigmaY: 60), child: Container()),
if (!appTheme.isClassic)
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return CustomPaint(
painter: BackgroundPainter(
primaryColor: colorScheme.primary,
secondaryColor: colorScheme.inversePrimary,
animation: _animation,
),
child: Container(),
);
}),
if (!appTheme.isClassic)
BackdropFilter(filter: ImageFilter.blur(sigmaX: 60, sigmaY: 60), child: Container()),
widget.mobileBuilder(context),
],
);
Expand Down

0 comments on commit fc01e55

Please sign in to comment.