194 lines
5.5 KiB
Dart
194 lines
5.5 KiB
Dart
import 'package:provider/provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
|
import 'flutter_flow/flutter_flow_theme.dart';
|
|
import 'flutter_flow/flutter_flow_util.dart';
|
|
import 'flutter_flow/internationalization.dart';
|
|
import 'index.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
GoRouter.optionURLReflectsImperativeAPIs = true;
|
|
usePathUrlStrategy();
|
|
|
|
await FlutterFlowTheme.initialize();
|
|
|
|
await FFLocalizations.initialize();
|
|
|
|
final appState = FFAppState(); // Initialize FFAppState
|
|
await appState.initializePersistedState();
|
|
|
|
runApp(ChangeNotifierProvider(
|
|
create: (context) => appState,
|
|
child: const MyApp(),
|
|
));
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
|
|
static _MyAppState of(BuildContext context) =>
|
|
context.findAncestorStateOfType<_MyAppState>()!;
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
Locale? _locale = FFLocalizations.getStoredLocale();
|
|
|
|
ThemeMode _themeMode = FlutterFlowTheme.themeMode;
|
|
|
|
late AppStateNotifier _appStateNotifier;
|
|
late GoRouter _router;
|
|
|
|
bool displaySplashImage = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_appStateNotifier = AppStateNotifier.instance;
|
|
_router = createRouter(_appStateNotifier);
|
|
|
|
Future.delayed(const Duration(milliseconds: 1000),
|
|
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
|
}
|
|
|
|
void setLocale(String language) {
|
|
setState(() => _locale = createLocale(language));
|
|
FFLocalizations.storeLocale(language);
|
|
}
|
|
|
|
void setThemeMode(ThemeMode mode) => setState(() {
|
|
_themeMode = mode;
|
|
FlutterFlowTheme.saveThemeMode(mode);
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp.router(
|
|
title: 'FREHub',
|
|
localizationsDelegates: const [
|
|
FFLocalizationsDelegate(),
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
locale: _locale,
|
|
supportedLocales: const [
|
|
Locale('pt'),
|
|
Locale('en'),
|
|
],
|
|
theme: ThemeData(
|
|
brightness: Brightness.light,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
thumbVisibility: WidgetStateProperty.all(false),
|
|
interactive: false,
|
|
thumbColor: WidgetStateProperty.resolveWith((states) {
|
|
if (states.contains(WidgetState.dragged)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
if (states.contains(WidgetState.hovered)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
brightness: Brightness.dark,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
thumbVisibility: WidgetStateProperty.all(false),
|
|
interactive: false,
|
|
thumbColor: WidgetStateProperty.resolveWith((states) {
|
|
if (states.contains(WidgetState.dragged)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
if (states.contains(WidgetState.hovered)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
themeMode: _themeMode,
|
|
routerConfig: _router,
|
|
);
|
|
}
|
|
}
|
|
|
|
class NavBarPage extends StatefulWidget {
|
|
const NavBarPage({super.key, this.initialPage, this.page});
|
|
|
|
final String? initialPage;
|
|
final Widget? page;
|
|
|
|
@override
|
|
_NavBarPageState createState() => _NavBarPageState();
|
|
}
|
|
|
|
/// This is the private State class that goes with NavBarPage.
|
|
class _NavBarPageState extends State<NavBarPage> {
|
|
String _currentPageName = 'homePage';
|
|
late Widget? _currentPage;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_currentPageName = widget.initialPage ?? _currentPageName;
|
|
_currentPage = widget.page;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final tabs = {
|
|
'homePage': const HomePageWidget(),
|
|
'settingsPage': const SettingsPageWidget(),
|
|
};
|
|
final currentIndex = tabs.keys.toList().indexOf(_currentPageName);
|
|
|
|
return Scaffold(
|
|
body: _currentPage ?? tabs[_currentPageName],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: currentIndex,
|
|
onTap: (i) => setState(() {
|
|
_currentPage = null;
|
|
_currentPageName = tabs.keys.toList()[i];
|
|
}),
|
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
|
selectedItemColor: FlutterFlowTheme.of(context).primary,
|
|
unselectedItemColor: FlutterFlowTheme.of(context).primaryText,
|
|
showSelectedLabels: false,
|
|
showUnselectedLabels: false,
|
|
type: BottomNavigationBarType.fixed,
|
|
items: <BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(
|
|
icon: const Icon(
|
|
Icons.home,
|
|
size: 24.0,
|
|
),
|
|
label: FFLocalizations.of(context).getText(
|
|
'mp6igsok' /* */,
|
|
),
|
|
tooltip: '',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: const Icon(
|
|
Icons.settings_rounded,
|
|
size: 24.0,
|
|
),
|
|
label: FFLocalizations.of(context).getText(
|
|
'sejj3t8w' /* */,
|
|
),
|
|
tooltip: '',
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|