mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
feat: change onboarding flow and remove theme switch button
This commit is contained in:
61
lib/app.dart
61
lib/app.dart
@@ -1,5 +1,8 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:developer' show log;
|
||||
|
||||
import 'package:apidash/screens/mobile/onboarding_screen.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
@@ -104,6 +107,10 @@ class _AppState extends ConsumerState<App> with WindowListener {
|
||||
class DashApp extends ConsumerWidget {
|
||||
const DashApp({super.key});
|
||||
|
||||
Future<bool> _checkOnboardingStatus() async {
|
||||
return await getOnboardingStatusFromSharedPrefs();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDarkMode =
|
||||
@@ -111,6 +118,7 @@ class DashApp extends ConsumerWidget {
|
||||
final workspaceFolderPath = ref
|
||||
.watch(settingsProvider.select((value) => value.workspaceFolderPath));
|
||||
final showWorkspaceSelector = kIsDesktop && (workspaceFolderPath == null);
|
||||
|
||||
return Portal(
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
@@ -133,24 +141,41 @@ class DashApp extends ConsumerWidget {
|
||||
}
|
||||
},
|
||||
)
|
||||
: Stack(
|
||||
children: [
|
||||
!kIsLinux && !kIsMobile
|
||||
? const App()
|
||||
: context.isMediumWindow
|
||||
? const MobileDashboard()
|
||||
: const Dashboard(),
|
||||
if (kIsWindows)
|
||||
SizedBox(
|
||||
height: 29,
|
||||
child: WindowCaption(
|
||||
backgroundColor: Colors.transparent,
|
||||
brightness:
|
||||
isDarkMode ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
: kIsMobile
|
||||
? FutureBuilder<bool>(
|
||||
future: _checkOnboardingStatus(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
log(snapshot.data.toString());
|
||||
final showOnboarding = snapshot.data ?? false;
|
||||
return showOnboarding
|
||||
? const MobileDashboard()
|
||||
: const OnboardingScreen();
|
||||
}
|
||||
return const MobileDashboard();
|
||||
},
|
||||
)
|
||||
: Stack(
|
||||
children: [
|
||||
!kIsLinux && !kIsMobile
|
||||
? const App()
|
||||
: context.isMediumWindow
|
||||
? const MobileDashboard()
|
||||
: const Dashboard(),
|
||||
if (kIsWindows)
|
||||
SizedBox(
|
||||
height: 29,
|
||||
child: WindowCaption(
|
||||
backgroundColor: Colors.transparent,
|
||||
brightness:
|
||||
isDarkMode ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import 'package:apidash/providers/settings_providers.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class ThemeSwitchButton extends StatelessWidget {
|
||||
const ThemeSwitchButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer(builder: (context, ref, child) {
|
||||
final settings = ref.watch(settingsProvider);
|
||||
|
||||
return IconButton(
|
||||
icon: settings.isDark
|
||||
? const Icon(
|
||||
Icons.dark_mode_rounded,
|
||||
color: Colors.indigo,
|
||||
)
|
||||
: const Icon(
|
||||
Icons.light_mode_rounded,
|
||||
color: Colors.yellow,
|
||||
),
|
||||
onPressed: () {
|
||||
ref.read(settingsProvider.notifier).update(isDark: !settings.isDark);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:apidash/screens/mobile/onboarding_screen.dart';
|
||||
import 'package:apidash/services/shared_preferences_services.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -21,50 +19,41 @@ class MobileDashboard extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _MobileDashboardState extends ConsumerState<MobileDashboard> {
|
||||
Future<bool> _checkOnboardingStatus() async {
|
||||
return await getOnboardingStatusFromSharedPrefs();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<bool>(
|
||||
future: _checkOnboardingStatus(),
|
||||
builder: (context, snapshot) {
|
||||
final railIdx = ref.watch(navRailIndexStateProvider);
|
||||
final isLeftDrawerOpen = ref.watch(leftDrawerStateProvider);
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.data == false) {
|
||||
return const OnboardingScreen();
|
||||
}
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: FlexColorScheme.themedSystemNavigationBar(
|
||||
context,
|
||||
opacity: 0,
|
||||
noAppBar: true,
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
) {
|
||||
final railIdx = ref.watch(navRailIndexStateProvider);
|
||||
final isLeftDrawerOpen = ref.watch(leftDrawerStateProvider);
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: FlexColorScheme.themedSystemNavigationBar(
|
||||
context,
|
||||
opacity: 0,
|
||||
noAppBar: true,
|
||||
),
|
||||
child: Stack(
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
children: [
|
||||
PageBranch(
|
||||
pageIndex: railIdx,
|
||||
),
|
||||
child: Stack(
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
children: [
|
||||
PageBranch(pageIndex: railIdx),
|
||||
if (context.isMediumWindow)
|
||||
AnimatedPositioned(
|
||||
bottom: railIdx > 2
|
||||
if (context.isMediumWindow)
|
||||
AnimatedPositioned(
|
||||
bottom: railIdx > 2
|
||||
? 0
|
||||
: isLeftDrawerOpen
|
||||
? 0
|
||||
: isLeftDrawerOpen
|
||||
? 0
|
||||
: -(72 + MediaQuery.paddingOf(context).bottom),
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 70 + MediaQuery.paddingOf(context).bottom,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
child: const BottomNavBar(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
: -(72 + MediaQuery.paddingOf(context).bottom),
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 70 + MediaQuery.paddingOf(context).bottom,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
child: const BottomNavBar(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/screens/common_widgets/theme_switch_button.dart';
|
||||
import 'package:apidash/screens/mobile/widgets/onboarding_slide.dart';
|
||||
import 'package:apidash/screens/screens.dart';
|
||||
import 'package:apidash/services/services.dart';
|
||||
@@ -42,7 +41,6 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
actions: [
|
||||
const ThemeSwitchButton(),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
@@ -143,9 +141,11 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
_onNextPressed();
|
||||
await setOnboardingStatusToSharedPrefs(
|
||||
isOnboardingComplete: true,
|
||||
);
|
||||
if (currentPageIndex == 2) {
|
||||
await setOnboardingStatusToSharedPrefs(
|
||||
isOnboardingComplete: true,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward_rounded,
|
||||
|
||||
@@ -37,5 +37,5 @@ Future<bool> getOnboardingStatusFromSharedPrefs() async {
|
||||
|
||||
Future<void> clearSharedPrefs() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(kSharedPrefSettingsKey);
|
||||
await prefs.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user