given this flutter/dart code import 'package:flutter/material.dart'; import…
- User
given this flutter/dart code import 'package:flutter/material.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:fluent_ui/fluent_ui.dart' as fluent; // Aliased import import 'dart:io'; import 'package:path/path.dart' as p;
void main() { runApp(const MyApp()); doWhenWindowReady(() { final win = appWindow; const initialSize = Size(1190, 750); win.minSize = initialSize; win.size = initialSize; win.maxSize = initialSize; win.alignment = Alignment.center; win.title = "Custom window with Flutter"; win.show(); }); }
const borderColor = fluent.Color(0xFF805306);
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { return fluent.FluentApp( title: 'Fluent UI Demo', theme: fluent.FluentThemeData( accentColor: fluent.Colors.blue, ), home: Scaffold( body: WindowBorder( color: borderColor, width: 1, child: const RightSide(), // RightSide widget handles language options ), ), ); } }
class RightSide extends StatefulWidget { const RightSide({super.key});
@override _RightSideState createState() => _RightSideState(); }
class _RightSideState extends State { List langOptions = []; String? selectedLanguage;
@override void initState() { super.initState(); fetchLangOptions(); // Fetch language options on startup }
Future fetchLangOptions() async { final directory = Directory('assets/lang'); // Directory path
try { final files = directory.listSync(); List<String> options = []; for (var file in files) { if (file is File) { String fileName = p.basenameWithoutExtension(file.path); // Get the file name without the extension if (fileName.length >= 2) { options.add(fileName.substring(0, 2)); // Get the first 2 characters } } } setState(() { langOptions = options; // Update the state with fetched options }); await setInitialSelectedLanguage(); // Set the initial selected language } catch (e) { print('Error reading directory: $e'); }}
Future setInitialSelectedLanguage() async { final file = File('assets/preferences.txt');
try { if (await file.exists()) { String firstLine = (await file.readAsLines()).first.trim(); // Get the last 2 characters of the first line String lastTwoChars = firstLine.length >= 2 ? firstLine.substring(firstLine.length - 2) : firstLine; // Check if the value exists in langOptions if (langOptions.contains(lastTwoChars)) { setState(() { selectedLanguage = lastTwoChars; // Update the selected language }); } } } catch (e) { print('Error reading preferences file: $e'); }}
Future updatePreferencesFile(String value) async { final file = File('assets/preferences.txt');
try { if (await file.exists()) { // Update the preferences file, writing the last 2 characters of the selected value await file.writeAsString(value, mode: FileMode.write); } } catch (e) { print('Error writing to preferences file: $e'); } - Assistant