ambito/lib/main.dart

164 lines
4 KiB
Dart
Raw Normal View History

2024-09-18 15:07:08 +02:00
import 'package:ambito/src/domain/entity/baumarten/baumarten.dart';
import 'package:ambito/src/domain/entity/massnahme/massnahme.dart';
import 'package:ambito/src/packages/ambito_api/base.dart';
import 'package:ambito/src/pages/actions/actions_page.dart';
import 'package:flutter/foundation.dart';
2024-09-13 21:32:34 +02:00
import 'package:flutter/material.dart';
2024-09-18 15:07:08 +02:00
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:isar/isar.dart';
import 'package:logger/logger.dart';
2024-09-13 21:32:34 +02:00
2024-09-18 15:07:08 +02:00
final String AmbitoToken = 'TFxO7vzBLVRCu9I3VMoHmTuCvSu8aCDi';
final Logger logger = Logger(
printer: PrettyPrinter(),
);
late Isar isar;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
/*Isar.open(
schemas: [BaumartenSchema, IdValueColorSchema, IdValueSchema],
directory: '',
);*/
await Isar.initialize();
const dir = Isar.sqliteInMemory;
const engine = kIsWeb ? IsarEngine.sqlite : IsarEngine.isar;
isar = Isar.open(
schemas: [BaumartenSchema, MassnahmeSchema],
directory: dir,
engine: engine,
inspector: true,
);
Future.wait([
BaseApi().getContent('baumarten'),
BaseApi().getContent('massnahmen'),
]);
2024-09-13 21:32:34 +02:00
2024-09-18 15:07:08 +02:00
//await BaseApi().getContent('baumarten');
//await BaseApi().getContent('massnahmen');
2024-09-13 21:32:34 +02:00
2024-09-18 15:07:08 +02:00
runApp(const Ambito());
}
class Ambito extends StatelessWidget {
const Ambito({super.key});
2024-09-13 21:32:34 +02:00
@override
Widget build(BuildContext context) {
2024-09-18 15:07:08 +02:00
return GetMaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(
fallbackFile: 'de',
basePath: 'i18n',
),
missingTranslationHandler: (key, locale) {
print("--- Missing Key: $key, languageCode: $locale");
},
),
],
2024-09-13 21:32:34 +02:00
title: 'Flutter Demo',
2024-09-18 15:07:08 +02:00
locale: const Locale('de'),
builder: FlutterI18n.rootAppBuilder(),
2024-09-13 21:32:34 +02:00
theme: ThemeData(
2024-09-18 15:07:08 +02:00
scaffoldBackgroundColor: Colors.white,
2024-09-13 21:32:34 +02:00
useMaterial3: true,
),
2024-09-18 15:07:08 +02:00
home: const MyHomePage(),
2024-09-13 21:32:34 +02:00
);
}
}
class MyHomePage extends StatefulWidget {
2024-09-18 15:07:08 +02:00
const MyHomePage({super.key});
2024-09-13 21:32:34 +02:00
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
2024-09-18 15:07:08 +02:00
String activeLink = '';
@override
void initState() {
activeLink = 'start';
super.initState();
2024-09-13 21:32:34 +02:00
}
@override
Widget build(BuildContext context) {
2024-09-18 15:07:08 +02:00
double fontSize = 16;
2024-09-13 21:32:34 +02:00
return Scaffold(
2024-09-18 15:07:08 +02:00
body: Column(
children: [
SizedBox(height: 50),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
LinkButton('start'),
LinkButton('database'),
LinkButton('designer'),
Image.asset(
'images/logo.png',
scale: 1.3,
2024-09-13 21:32:34 +02:00
),
2024-09-18 15:07:08 +02:00
LinkButton('service'),
LinkButton('network'),
LinkButton('contact'),
2024-09-13 21:32:34 +02:00
],
),
2024-09-18 15:07:08 +02:00
SizedBox(height: 50),
Expanded(
child: getContent(),
),
],
));
}
Widget getContent() {
if (activeLink == 'database') {
return ActionsPage();
}
return Text(activeLink);
}
Widget LinkButton(String link) {
double fontSize = 16;
return TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
return Colors.white;
}),
),
onPressed: () {
setState(() {
activeLink = link;
});
},
child: Text(
context.translate('page.start.links.$link.title'),
style: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: (activeLink == link)
? Colors.grey.shade400
: Colors.grey.shade800,
),
2024-09-13 21:32:34 +02:00
),
);
}
}
2024-09-18 15:07:08 +02:00
extension ContextI18n on BuildContext {
translate(String key) {
return FlutterI18n.translate(this, key);
}
}