144 lines
3.8 KiB
Dart
144 lines
3.8 KiB
Dart
import 'dart:io' show Platform;
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:quotegen_client/pages/gallery/page.dart';
|
|
import 'package:quotegen_client/pages/home/page.dart';
|
|
import 'package:quotegen_client/providers/backend_status_provider.dart';
|
|
import 'package:quotegen_client/providers/form_provider.dart';
|
|
import 'package:quotegen_client/providers/gallery_provider.dart';
|
|
import 'package:quotegen_client/providers/render_provider.dart';
|
|
import 'package:quotegen_client/providers/session_provider.dart';
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
|
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Initialize mobile ads (AdMob) only on mobile platforms (not web or macOS)
|
|
if (!kIsWeb && !Platform.isMacOS) {
|
|
await MobileAds.instance.initialize();
|
|
}
|
|
|
|
await Hive.initFlutter();
|
|
await Hive.openLazyBox<String>("gallery");
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (_) => FormProvider()),
|
|
ChangeNotifierProvider(create: (_) => SessionProvider()),
|
|
ChangeNotifierProvider(create: (_) => RenderProvider()),
|
|
ChangeNotifierProvider(create: (_) => GalleryProvider()),
|
|
ChangeNotifierProvider(create: (_) => BackendStatusProvider()),
|
|
],
|
|
child: ShadcnApp.router(
|
|
title: 'TweetForge',
|
|
routerConfig: _router,
|
|
scaling: {
|
|
TargetPlatform.iOS: AdaptiveScaling.only(
|
|
sizeScaling: 1.3,
|
|
textScaling: 1.2,
|
|
radiusScaling: 1.3
|
|
),
|
|
TargetPlatform.android: AdaptiveScaling.only(
|
|
sizeScaling: 1.2,
|
|
textScaling: 1.02,
|
|
radiusScaling: 1.0
|
|
),
|
|
}[defaultTargetPlatform] ?? AdaptiveScaling.mobile,
|
|
theme: ThemeData(
|
|
colorScheme: ColorSchemes.darkGray.indigo,
|
|
surfaceOpacity: 1,
|
|
|
|
),
|
|
));
|
|
}
|
|
}
|
|
|
|
GoRouter _router = GoRouter(
|
|
initialLocation: "/",
|
|
routes: [
|
|
|
|
ShellRoute(
|
|
builder: (context, state, child) {
|
|
return _AppShell(child: child);
|
|
},
|
|
routes: [
|
|
HomePage.route,
|
|
GalleryPage.route,
|
|
]
|
|
),
|
|
|
|
|
|
|
|
],
|
|
);
|
|
|
|
class _AppShell extends StatelessWidget {
|
|
final Widget child;
|
|
const _AppShell({required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final location = GoRouterState.of(context).uri.path;
|
|
final index = location.startsWith("/gallery") ? 1 : 0;
|
|
|
|
double bottomPadding = MediaQuery.of(context).padding.bottom;
|
|
|
|
return Column(
|
|
children: [
|
|
Expanded(child: child),
|
|
|
|
NavigationBar(
|
|
index: index,
|
|
onSelected: (i) {
|
|
if (i == 0) context.go("/");
|
|
else if (i == 1) context.go("/gallery");
|
|
},
|
|
labelType: NavigationLabelType.all,
|
|
children: [
|
|
NavigationItem(
|
|
label: Text(
|
|
"Editor"
|
|
),
|
|
child: Icon(
|
|
LucideIcons.house
|
|
),
|
|
),
|
|
NavigationItem(
|
|
label: Text(
|
|
"Gallery"
|
|
),
|
|
child: Icon(
|
|
LucideIcons.galleryHorizontal
|
|
),
|
|
),
|
|
// NavigationItem(
|
|
// label: Text(
|
|
// "Settings"
|
|
// ),
|
|
// child: Icon(
|
|
// LucideIcons.settings
|
|
// ),
|
|
// )
|
|
],
|
|
),
|
|
|
|
if (defaultTargetPlatform == TargetPlatform.android)
|
|
Gap(bottomPadding)
|
|
|
|
],
|
|
);
|
|
}
|
|
}
|