class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
so that there is a header bar of height 40px
1 content area below the header bar
Assistant
To adjust your Flutter app to include a header bar with a fixed height of 40 pixels and modify the content area accordingly, you can achieve this by making some changes to the layout. Here's the revised code:
dart
User
remove the left hand column
Assistant
If you want to remove the left-hand column (sidebar) from your app, you'll need to modify the layout in the MyApp widget. Here’s the updated code without the left-hand sidebar:
dart
User
move the header bar below the title buttons
Assistant
To move the header bar below the title buttons, you'll need to make some modifications to the layout within the RightSide widget. Specifically, you should reposition the header bar so that it appears underneath the window's title bar buttons (minimize, maximize, close).
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
add centered text in the header bar "Text Holder"
Assistant
To add centered text in the header bar labeled "Text Holder", you can replace the existing Expanded widget in the header with a Center widget that contains a Text widget.
Here's the modified code with the centered text in the header bar:
dart
User
create a dropdown menu at the rhs of the header bar, keep the header text centered
Assistant
To create a dropdown menu at the right-hand side of the header bar while keeping the header text centered, you can use a combination of a Row and DropdownButton widgets in the header bar. You will place the Text widget centered in the header bar, and the dropdown menu on the right.
Here's the modified code:
dart
User
the items in the dropdown will come from the the first 2 charactures of the file name in the assets/lang folder
Assistant
To populate your dropdown menu with the first two characters of each filename in a specific directory (like assets/lang), you'll need to follow these steps:
List Files in the Directory: Use the Directory class from Dart's dart:io library to read the filenames in the assets/lang folder.
Extract First Two Characters: Extract the first two characters from each filename and use those to populate your dropdown menu.
Important Note:
You need to ensure that your Flutter app has appropriate access to read files from the specified directory. However, note that when running your app in a mobile/desktop environment, it often relies on the assets declared in your pubspec.yaml, not directly on the filesystem.
Example Code Snippet
Below is a modified version of your previous application. It assumes the filenames are loaded during the initialization of the RightSide class and uses FutureBuilder to display the dropdown once the filenames are loaded.
Make sure to add import 'dart:io'; at the top of your file for file system access.
Here's the modified code:
dart
User
change the header bar color to black
reduce the width of the dropdown and move slightly to the left
Assistant
To change the header bar color to black, reduce the width of the dropdown menu, and move it slightly to the left, you can make a few adjustments in the RightSide widget. Specifically, you need to modify the header bar's background color, adjust the dropdown's width, and set its alignment slightly to the left using padding or by adjusting its position in the layout.
Here’s how you can adjust your existing code:
dart
User
reduce the width of the dropdown and make the text of the dropdown white
Assistant
To reduce the width of the dropdown and make the text of the dropdown white, you can adjust the SizedBox width for the dropdown and use a TextStyle in the dropdown items to set the text color to white.
Here's the updated code with those modifications:
dart
User
move the dropdown more to the right and reduce the width by 50%
Assistant
To move the dropdown more to the right and reduce its width by 50%, you can adjust the SizedBox width and the padding around the dropdown. Here's the updated code where the dropdown width is set to approximately half of its previous width (40 instead of 80), and additional padding is added to push it further to the right.
Here's the modified code:
dart
User
is there a better alternative to the dropdown that better mirrors that of a windows app
Assistant
If you're looking for a dropdown-like component that more closely mimics a typical Windows application experience, you might consider using a PopupMenuButton. This widget provides similar functionality to a dropdown but is often more visually aligned with desktop application conventions.
Benefits of Using PopupMenuButton:
Familiarity: This control resembles the menu options found in traditional desktop applications, making it more user-friendly for users familiar with Windows.
Flexibility: You can customize it more easily to include icons, grouping, or nesting of options.
Integration with the Title Bar: Since PopupMenuButton opens a menu rather than a dropdown, it tends to visually integrate better with buttons typically found in title bars or toolbars.
Example Implementation
Below is an example of how to implement a PopupMenuButton in place of the dropdown menu you've been using.
Replace your dropdown portion with this:
dart
User
The returned type 'Future<List<PopupMenuItem>>' isn't returnable from a 'List<PopupMenuEntry>' function, as required by the closure's context.
Assistant
The error you're encountering is due to the fact that itemBuilder in the PopupMenuButton expects a synchronous return of type List<PopupMenuEntry<T>>, while you are providing a Future<List<PopupMenuEntry<T>>> because you're using fetchLangOptions in an asynchronous manner.
To solve this, you'll want to fetch the language options beforehand (e.g., during the initState of the stateful widget) and store them in a list that you can then use in itemBuilder. This way, the itemBuilder can work synchronously.
Here's the corrected code:
Store the Language Options: Use a variable to store the options and initialize it when the widget is created.
Update the UI: Use a FutureBuilder if you want to handle loading states while fetching data or directly read from the pre-fetched data.
Here's the updated code:
dart
User
no thats not good how about including the flui ui drop box
Assistant
If you're looking to use the Fluent UI package's dropdown component for a more native Windows-like appearance, you can use the Fluent UI package for Flutter, which provides a set of controls styled like Windows apps.
Adding Fluent UI to Your Project
First, you would need to add the Fluent UI package to your pubspec.yaml file. Ensure you have the latest version:
yaml
dependencies:
flutter:
sdk: flutter
fluent_ui: ^3.0.0 # Check for the latest version on pub.dev
After adding the dependency, make sure to run flutter pub get to install it.
Implementing Fluent UI ComboBox
Now, you can replace your existing dropdown or menu with a Fluent UI ComboBox. Here's how you can integrate the Fluent UI ComboBox into your app:
Sample Code
Here's an example of how to implement the Fluent UI ComboBox:
dart
User
The name 'Colors' is defined in the libraries 'package:fluent_ui/src/styles/color.dart (via package:fluent_ui/fluent_ui.dart)' and 'package:flutter/src/material/colors.dart (via package:flutter/material.dart)'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.
Assistant
The error you are encountering arises from a naming conflict between the Colors class in the fluent_ui package and the Colors class in the flutter package. Both packages define a Colors class, leading to ambiguity when you refer to Colors directly in your code.
Solution
To resolve this, you can alias one of the imports so that you can easily distinguish between the two. For example, you can import fluent_ui with an alias while keeping the flutter import unaliased. This allows you to clearly specify which Colors you intend to use.
Here's how you can modify the imports:
dart
User
The method 'ComboBox' isn't defined for the type '_RightSideState'.
Try correcting the name to the name of an existing method, or defining a method named 'ComboBox'.
Assistant
If you are encountering the error stating that the ComboBox isn't defined for the type _RightSideState, it may be due to the fluent_ui package not being imported correctly, or it could be that an appropriate widget is not present in the version of the fluent_ui package you are using.
Steps to Resolve
Check Dependency: Ensure that you have added fluent_ui to your pubspec.yaml and that you are using a compatible version. For instance, at the time of writing, using fluent_ui version 3.0.0 or later is recommended.
yaml
dependencies:
fluent_ui: ^3.0.0
Using the Correct Widget: As of the latest versions of the fluent_ui package, the widget for a dropdown-like component is typically referred to as ComboBox. Make sure your imports are correct and that you're indeed using the ComboBox widget provided by fluent_ui.
Importing the Necessary Packages: Ensure your import statement specifically pulls in fluent_ui. Here's a corrected code snippet with the potential issues addressed and a fresh structure for your ComboBox.
Here’s your updated code integrating the ComboBox:
dart
User
on sstartup
Assistant
To display the ComboBox options fetched from a directory upon startup, you need to ensure that the fetching of language options happens as soon as the application starts. You already have some code in place, but we will emphasize that the ComboBox is populated when the UI is built.
Here's a breakdown of the necessary steps:
Initialization on Startup: In the initState method of the RightSide widget, you'll perform the fetch operation.
Display the ComboBox Correctly: Ensure that the ComboBox reflects the loaded options once they are available.
Here’s how you can implement this in the existing context of your app:
Modified Code
Here’s your updated RightSide widget with emphasis on initializing ComboBox options on startup:
dart
User
on startup the selected item in the dropdown should be set to the last 2 chars of line 1 of the assets/preferences.txt file
Assistant
To set the selected item in the ComboBox to the last two characters of the first line in an assets/preferences.txt file on startup, you will modify the code to read this file during the initialization of your RightSide widget.
Here's how you can implement this:
Read the preferences.txt File: You'll read the first line from the file on startup.
Extract Last Two Characters: Get the last two characters from this line and set it as the selected value in the ComboBox, provided that this value exists in the langOptions.
Here’s how to implement this functionality:
Complete Code Example
dart
User
reduce the width of the dropdown
Assistant
To reduce the width of the Fluent UI ComboBox (dropdown), you can wrap the ComboBox in a SizedBox and specify the desired width. This allows you to control the size of the dropdown without affecting the overall layout.
Here's how to modify the existing code to reduce the width of the ComboBox:
Updated Code Snippet
Here’s the relevant part of the code with a SizedBox added around the ComboBox to reduce its width:
dart
...
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 120, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
...
Key Modifications:
Use of SizedBox: The ComboBox is now wrapped in a SizedBox where you can set the width property. In this case, I've set it to 120. You can adjust this value to fit your design.
Maintaining Padding: The Padding around the SizedBox ensures that the ComboBox has some space to the right.
Result:
By wrapping the ComboBox in a SizedBox, you can control its width. Feel free to experiment with the width value to achieve the desired look and feel for your application's user interface.
User
full code please
Assistant
Certainly! Below is the complete code for your Flutter application, integrating the Fluent UI ComboBox, which displays language options fetched from an assets/lang directory and sets the selected item based on the last two characters of the first line in an assets/preferences.txt file. The width of the ComboBox has been reduced by wrapping it in a SizedBox.
Complete Code
dart
User
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#ed082 relayoutBoundary=up25 OVERFLOWING:
creator: Row ← Padding ← Container ← DefaultTextStyle ← Builder ← Builder ← Center ←
DefaultTextStyle ← AnimatedDefaultTextStyle ← IconTheme ← Builder ← Padding ← ⋯
parentData: offset=Offset(11.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=72.0, 0.0<=h<=38.0)
size: Size(72.0, 32.0)
direction: horizontal
mainAxisAlignment: spaceBetween
mainAxisSize: min
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
Assistant
The error message you're encountering indicates that the contents of a Row are exceeding the available horizontal space. This typically happens when one or more of the children inside the Row are sized too large for the available width.
To fix this issue, you can take the following steps:
Use Expanded or Flexible Widgets: Wrap any child widgets within the Row that might be causing this overflow in an Expanded or Flexible widget. This allows them to take up the remaining space and prevents any overflow.
Check Fixed Widths: If any widgets are given a fixed width that makes the Row exceed available space, consider removing that fixed width or replacing it with a width that is calculated based on the available space or wrapping it in a Flexible.
Replace Row with a Column: If your layout allows, consider using a Column instead of a Row, especially if you don't need a horizontal layout.
Here's how you can implement these suggestions in the code you provided:
Updated Code with Suggestions
I will use Expanded for the ComboBox, and ensure that children do not have a fixed width that might cause overflow.
dart
User
next
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'dart:io';
import 'package:path/path.dart' as p;
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');
code
Assistant
To write the selected item from the ComboBox (dropdown) back to the assets/preferences.txt file, you will need to implement the logic to open the file and update its contents when a new selection is made. This involves using Dart's file I/O capabilities to write data to the file.
Here’s a step-by-step update for your existing code:
Update the onChanged Callback: Modify the onChanged function of the ComboBox to write the new selection back to preferences.txt.
Write to the File: When the selection changes, update the file with the last two characters of the selected language.
Updated Code Snippet
Here's how you can implement this in the existing structure:
dart
User
place a button 100px from the lhs under the header bar with space between the header and the new button. The text for the button is initialize
Assistant
To place a button 100 pixels from the left-hand side (LHS) under the header bar with some space between the header and the new button, you can follow these steps:
Use a Container or Padding: You can wrap the button in a Container and specify the left margin or padding.
Text for the Button: Use a TextButton, FluentButton, or similar to create the button with the label "Initialize".
Add Space: You can also use a SizedBox to provide some vertical space between the header and the button.
Here’s how to modify your existing code to include this button:
Updated Code
dart
User
The function 'FluentButton' isn't defined.
Try importing the library that defines 'FluentButton', correcting the name to the name of an existing function, or defining a function named 'FluentButton'.
Assistant
The FluentButton class isn't part of the fluent_ui package. Instead, the Fluent UI library provides several button types, including Button, TextButton, and FilledButton. You can use one of these alternatives for your button implementation.
In this case, I suggest using Button for a standard button, which is styled according to Fluent UI principles. Here’s the code updated to use Button instead of FluentButton.
Complete Code with Button
dart
User
increase the size of the button and bold text
Assistant
To increase the size of the button in Fluent UI and to make its text bold, you can specify the style property for the button, and use the TextStyle class to set the font weight to FontWeight.bold.
You can also use padding or customize the button's height and width directly if needed. Below is the modified code to achieve that.
Updated Code Snippet
Here's how to integrate these changes:
dart
User
The argument type 'ButtonStyle' can't be assigned to the parameter type 'ButtonStyle?'.
Assistant
The error you're experiencing, "The argument type 'ButtonStyle' can't be assigned to the parameter type 'ButtonStyle?'", indicates that the Button widget in the Fluent UI package expects its style to be passed differently than I initially provided.
In the context of Fluent UI for Flutter, you can directly define the button's style in a slightly different manner. Here’s how you can specify the padding with built-in styles.
Updated Code Example
Here’s the complete code with appropriate button styling:
dart
User
lets use a material button
Assistant
If you'd like to use a Material Design button instead of the Fluent UI button, you can replace the fluent.Button with ElevatedButton, TextButton, or OutlinedButton from Flutter's Material library.
Complete Code Example Using Material Button
In this example, I'll be using ElevatedButton, which is a commonly used button style in Material Design and provides a raised button appearance. Here's the updated code with the Material button implementation:
Header Bar: A new Container is added at the top of the RightSide widget with a fixed height of 40 pixels. You can customize the header's color and contents according to your needs.
Content Area: The area below the header is structured within an Expanded widget to dynamically fill the remaining space.
This layout results in a clean design featuring a header followed by a flexible content area, maintaining the original sidebar design. You can further decorate or enhance the header and content as per your requirements.
Removed Left Sidebar: The LeftSide widget and its reference in the Row of the MyApp widget have been removed.
Updated Layout: The RightSide widget now operates independently, as it contains both the header and content area.
Result:
You now have a single column layout that features a header at the top and a content area below it, removing any left sidebar from the UI. You can further customize the header and the content area as per your requirements.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color(0xFFFFD500);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatelessWidget {
const RightSide({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.blue, // Set a color for the header bar
child: Row(
children: [
Expanded(child: Container()), // Optional area for spacing
// You can add more widgets here if needed
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, backgroundEndColor],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Place Window Title Buttons Above the Header Bar: The WindowTitleBarBox is added at the top of the RightSide widget, ensuring that it appears before the header bar.
Moved Header Bar: The header bar (the Container with height 40) is now below the WindowTitleBarBox, thus placing it underneath the title buttons.
Result:
Now, the window title buttons (minimize, maximize, close) are situated above the header bar while the content area remains below both sections. You can further customize the contents of the header bar as necessary.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatelessWidget {
const RightSide({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.blue, // Set a color for the header bar
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Centered Text in Header Bar: Used a Center widget inside the header bar's Container. Within this Center widget, added a Text widget displaying "Text Holder".
Text Styling: Set the text color to white, adjusted the font size to 16, and made the text bold using the TextStyle.
Result:
The header bar will now display the text "Text Holder" centered within the bar, providing clear visibility against the blue background. You can further customize text styling or positioning as needed.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatelessWidget {
const RightSide({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.blue, // Set a color for the header bar
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
items: <String>['Option 1', 'Option 2', 'Option 3']
.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newValue) {
// Handle dropdown value change
},
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.white, // Dropdown icon color
),
dropdownColor: Colors.blue, // Dropdown background color
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Dropdown Menu: A DropdownButton has been added to the right side of the header bar. It uses a simple list of options (e.g., "Option 1", "Option 2", "Option 3").
Centering: The header text ("Text Holder") is still centered by using an Expanded widget around the Center widget.
Dropdown Styling:
DropdownButtonHideUnderline: Hides the underline of the dropdown button.
icon: Sets a white color for the dropdown icon.
dropdownColor: Sets the dropdown menu's background color to blue, matching the header bar color.
Result:
The header bar now displays "Text Holder" centered, with a dropdown menu on the right side. You can select an option from the dropdown, and you would handle the selection logic within the onChanged callback of the DropdownButton. Adjust the options as needed for your application.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
Future<List<String>> fetchLangOptions() async {
final directory = Directory('assets/lang'); // Directory path
List<String> options = [];
try {
final files = directory.listSync();
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
}
}
}
} catch (e) {
print('Error reading directory: $e');
}
return options;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.blue, // Set a color for the header bar
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Dropdown Button
FutureBuilder<List<String>>(
future: fetchLangOptions(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Text('No Options');
}
return DropdownButtonHideUnderline(
child: DropdownButton<String>(
items: snapshot.data!.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newValue) {
// Handle dropdown value change
},
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.white, // Dropdown icon color
),
dropdownColor: Colors.blue, // Dropdown background color
),
);
},
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Explanation:
FutureBuilder: The dropdown is wrapped in a FutureBuilder, which asynchronously loads the file names.
Fetching File Names: The fetchLangOptions method lists all files in the assets/lang directory and extracts the first two characters of each filename as dropdown items.
Error Handling: Basic error handling has been added to handle cases where the directory cannot be read.
Circular Progress Indicator: While loading, a circular progress indicator will be shown.
Important Note:
Make sure to replace the relative path ('assets/lang') in the Directory with your actual path as needed (make sure the path is accessible). This code assumes it runs in a desktop environment where you can access the filesystem directly; it won't work in a standard mobile app context as mobile apps can't generally read files from the app's asset bundle this way. You may need to adjust this logic to fit into how you plan to manage translations or language files in your application.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
Future<List<String>> fetchLangOptions() async {
final directory = Directory('assets/lang'); // Directory path
List<String> options = [];
try {
final files = directory.listSync();
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
}
}
}
} catch (e) {
print('Error reading directory: $e');
}
return options;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Dropdown Button with reduced width and slight left shift
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 100, // Set a fixed width for the dropdown
child: FutureBuilder<List<String>>(
future: fetchLangOptions(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Text('No Options');
}
return DropdownButtonHideUnderline(
child: DropdownButton<String>(
items: snapshot.data!.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newValue) {
// Handle dropdown value change
},
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.white, // Dropdown icon color
),
dropdownColor: Colors.black, // Dropdown background color
),
);
},
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Header Bar Color: The Container for the header bar has its color set to Colors.black.
Dropdown Menu: The width of the dropdown has been reduced by wrapping it in a SizedBox with a fixed width of 100.
Position Adjustment: A Padding widget is added around the dropdown to create space on the right side, effectively moving it slightly to the left.
Result:
The header bar will now be black, with "Text Holder" centered and a narrower dropdown menu on the right-hand side, slightly shifted to the left for a more compact appearance. You can further adjust the width and padding values according to your design preferences.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
Future<List<String>> fetchLangOptions() async {
final directory = Directory('assets/lang'); // Directory path
List<String> options = [];
try {
final files = directory.listSync();
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
}
}
}
} catch (e) {
print('Error reading directory: $e');
}
return options;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Dropdown Button with reduced width and slight left shift
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 80, // Set a reduced fixed width for the dropdown
child: FutureBuilder<List<String>>(
future: fetchLangOptions(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Text('No Options');
}
return DropdownButtonHideUnderline(
child: DropdownButton<String>(
items: snapshot.data!.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.white), // Set dropdown item text color to white
),
);
}).toList(),
onChanged: (String? newValue) {
// Handle dropdown value change
},
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.white, // Dropdown icon color
),
dropdownColor: Colors.black, // Dropdown background color
),
);
},
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Dropdown Width Reduced: The width of the SizedBox wrapping the dropdown has been set to 80, which reduces the width of the dropdown.
Dropdown Item Text Color: The text color for the dropdown items is set to white using style: TextStyle(color: Colors.white) in the DropdownMenuItem.
Result:
The dropdown is now narrower, and its item text color is white, providing better contrast against the black header bar. You can adjust the width of the dropdown further as needed, depending on the specific lengths of the items you expect in your application.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
Future<List<String>> fetchLangOptions() async {
final directory = Directory('assets/lang'); // Directory path
List<String> options = [];
try {
final files = directory.listSync();
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
}
}
}
} catch (e) {
print('Error reading directory: $e');
}
return options;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Dropdown Button with reduced width and slight left shift
Padding(
padding: const EdgeInsets.only(right: 32.0), // Increased right padding
child: SizedBox(
width: 40, // Set the width to 50% of previous (40 instead of 80)
child: FutureBuilder<List<String>>(
future: fetchLangOptions(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Text('No Options');
}
return DropdownButtonHideUnderline(
child: DropdownButton<String>(
items: snapshot.data!.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.white), // Set dropdown item text color to white
),
);
}).toList(),
onChanged: (String? newValue) {
// Handle dropdown value change
},
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.white, // Dropdown icon color
),
dropdownColor: Colors.black, // Dropdown background color
),
);
},
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Dropdown Width: The width of the SizedBox wrapping the dropdown has been reduced to 40.
Dropdown Position: Increased the right padding around the dropdown by changing it to 32.0. This pushes the dropdown further to the right for better positioning.
Result:
The dropdown will now have a width of 40, making it more compact, and it will be positioned more prominently to the right side of the header bar. You can further fine-tune the padding and width values according to your design preferences.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
Future<List<String>> fetchLangOptions() async {
final directory = Directory('assets/lang'); // Directory path
List<String> options = [];
try {
final files = directory.listSync();
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
}
}
}
} catch (e) {
print('Error reading directory: $e');
}
return options;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Popup Menu Button
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, color: Colors.white), // Set the menu icon
onSelected: (String value) {
// Handle the selected value
print("Selected: $value");
},
itemBuilder: (BuildContext context) {
return fetchLangOptions().asStream().map((options) {
return options.map((String value) {
return PopupMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.white), // Set menu item text color
),
);
}).toList();
}).first;
},
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Explanation:
PopupMenuButton: Instead of a dropdown, I've used PopupMenuButton<String>, which opens a menu when clicked.
Icon: The icon for the popup menu can resemble typical context menus in Windows applications. You can customize the icon or use one that better fits your design.
Dynamic Menu Items: The menu items are populated similarly to how we populated the dropdown before. The itemBuilder creates PopupMenuItems based on filenames from the specified directory.
Color & Style: The menu item's text color is set to white to match the application's visual style.
Result:
Using a PopupMenuButton provides a more native-like Windows experience, making it feel more integrated into your application. It allows for easier expansion in the future (e.g., adding icons next to menu items, grouping items, etc.) and generally fits better in a toolbar or title bar context. You can further customize the menu and its items as needed.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
@override
void initState() {
super.initState();
fetchLangOptions();
}
Future<void> 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
});
} catch (e) {
print('Error reading directory: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Popup Menu Button
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, color: Colors.white), // Set the menu icon
onSelected: (String value) {
// Handle the selected value
print("Selected: $value");
},
itemBuilder: (BuildContext context) {
return langOptions.map((String value) {
return PopupMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.white), // Set menu item text color
),
);
}).toList();
},
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
State Management: The langOptions list is now a state variable, initialized in initState().
Data Fetching: The fetchLangOptions function populates langOptions and calls setState to update the UI.
Popup Menu Button: The itemBuilder for the PopupMenuButton now uses the pre-fetched langOptions, allowing it to run synchronously and resolving the type error.
Result:
Using the PopupMenuButton, you get a more Windows-like menu interaction, and the popup is populated with your directory's language options. This structure also ensures that your code adheres to Flutter's reactive framework principles by using state management appropriately.
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Color(0xFF805306);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FluentApp(
title: 'Fluent UI Demo',
theme: FluentThemeData(
accentColor: Colors.blue,
),
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions();
}
Future<void> 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
});
} catch (e) {
print('Error reading directory: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue;
});
},
items: langOptions.map((String value) {
return ComboBoxItem<String>(
value: value,
child: Text(value, style: TextStyle(color: Colors.black)), // Set text color
);
}).toList(),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Explanation:
Fluent UI Dependency: This code assumes you have the fluent_ui package added to your project.
ComboBox Widget: The ComboBox is used to create a dropdown-like experience. You can set options using the items property, which contains ComboBoxItem.
On Select: The onChanged callback updates the state with the selected language.
Styling: The ComboBox items are styled to fit within the dark header bar.
Result:
Using the Fluent UI ComboBox gives you a sleek and professional-looking dropdown that feels at home in Windows applications. This implementation allows you to maintain a consistent UI design while providing the necessary functionality. Adjust the colors and styles as needed to fit your overall application theme!
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent; // Use an alias for fluent_ui
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({Key? key}) : super(key: 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: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = fluent.Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = fluent.Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions();
}
Future<void> 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
});
} catch (e) {
print('Error reading directory: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue;
});
},
items: langOptions.map((String value) {
return ComboBoxItem<String>(
value: value,
child: Text(value), // No color specified, default behavior
);
}).toList(),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Aliased Import: The fluent_ui package is imported with the alias fluent, allowing you to clearly distinguish between Colors from fluent_ui and flutter.
Usage of Aliased Colors: All instances where Colors is referenced now use the fluent prefix, e.g., fluent.Colors.black.
Result:
After making these changes, you should no longer face the conflict between the two Colors definitions, and you can easily use everything from both libraries without ambiguity. This code will still provide the Fluent UI styled combo box for selection, fitting well into the overall application design.
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({Key? key}) : super(key: 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: RightSide(), // Only the RightSide widget is now used
),
),
);
}
}
const backgroundStartColor = fluent.Color.fromARGB(255, 255, 255, 255);
const backgroundEndColor = fluent.Color(0xFFF6A00C);
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions();
}
Future<void> 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
});
} catch (e) {
print('Error reading directory: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue;
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value), // Set text color
);
}).toList(),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, Color.fromARGB(255, 255, 255, 255)],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Aliased Import: I've imported fluent_ui as fluent, clarifying which components are from that library.
Usage of ComboBox: Updated to use fluent.ComboBox and fluent.ComboBoxItem to prevent name collisions.
Summary
This code will utilize the Fluent UI ComboBox without errors regarding the widget's definition. Ensure that you run flutter pub get to update your dependencies before testing the implementation. If you are still experiencing any issues, double-check the version of the fluent_ui library for compatibility with the given 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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
// Fetch language options on startup
fetchLangOptions();
}
Future<void> 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
}
}
}
// Update the state with fetched options
setState(() {
langOptions = options;
});
} catch (e) {
print('Error reading directory: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value), // Displaying the dropdown option
);
}).toList(),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Explanation:
Fetch Language Options: The fetchLangOptions function is called in the initState, ensuring that the available options are populated as soon as the RightSide widget is initialized.
Updating State: After fetching the options, the state is updated to reflect these, thus ensuring the ComboBox has its items ready to go when the UI is built.
Displaying ComboBox: The ComboBox widget now displays options straight from the populated langOptions list.
Summary:
Using the Fluent UI framework's ComboBox ensures a native look, and by fetching the languages on startup, you provide a seamless user experience. Adjust this implementation according to your app's needs, especially the directory structure for fetching language files.
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> setInitialSelectedLanguage() async {
final file = File('assets/preferences.txt');
try {
if (await file.exists()) {
List<String> lines = await file.readAsLines();
if (lines.isNotEmpty) {
String firstLine = lines[0].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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Explanation:
Loading Preferences: The setInitialSelectedLanguage method reads the first line from assets/preferences.txt.
Extracting Last Two Characters: It trims the line and extracts the last two characters. If they exist in the defined langOptions, the selectedLanguage state variable gets updated.
Integration with ComboBox: The ComboBox uses selectedLanguage as its value. The ComboBox will reflect the loaded value from the preferences file.
Notes:
Ensure the path assets/preferences.txt is correctly pointing to your preferences file.
Don’t forget to add the appropriate permissions if needed, especially when accessing the file system on different platforms.
Make sure you have error handling in case the file does not exist or cannot be read. This will help prevent crashes during runtime.
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
// Fetch language options on startup
fetchLangOptions();
}
Future<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 100, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Components of the Code:
File Reading: The app reads the preferences.txt file, retrieves the first line, and sets the ComboBox's selected value based on the last two characters of this line.
Combobox Configuration: The ComboBox width is set to 100 pixels using a SizedBox.
State Management: The app updates state via setState to reflect changes in language selection and initial values.
Usage:
Ensure that you have:
Added Fluent UI dependency in your pubspec.yaml.
The assets/lang directory with applicable language files.
The assets/preferences.txt file with at least one line of text.
This complete code provided should give you a robust foundation for your Flutter application. If you have further adjustments or need more features, please let me know!
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 100, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('Select Language'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Width Control: The ComboBox is now wrapped in a SizedBox with a width of 100, allowing you to control its width while keeping the layout intact.
Notes:
Adjust Width: Feel free to adjust the width of the SizedBox as per your design requirements.
Error Handling: Make sure that you have proper error handling in place for reading from the filesystem, especially for the preferences file.
Assets: Ensure that your assets/lang and assets/preferences.txt files are correctly set up in your Flutter project's directory and declared in your pubspec.yaml.
This code structure should eliminate any overflow issues and provide a clean, functional interface for your application. If you run into further issues, let me know!
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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
when selected the selected item text of the dropdown should be written to the last 2 chars of line 1 of the preferences.txt file
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Update Preferences on Selection: The updatePreferencesFile method writes the selected item to preferences.txt when the user changes the selection in the ComboBox.
Triggering the Write Operation: Inside the onChanged method of the ComboBox, after updating the state, it calls updatePreferencesFile with the selected value to save it.
Notes:
Make sure the file paths (assets/lang and assets/preferences.txt) are configured properly within your project.
File permissions may be necessary based on the platform you're running (especially on mobile platforms).
This complete code will now read the options from your assets directory and write the selected language back to the preferences file, maintaining a responsive UI. If you have further questions or adjustments, feel free to ask!
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
SizedBox(height: 20), // Space between the header and button
// Button placed 100px from the left
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 100.0), // 100px space from the left
child: fluent.FluentButton(
onPressed: () {
// Action for the button
print('Initialize button pressed.');
},
child: const Text('Initialize'), // Button text
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Summary of Key Changes:
Added Button: A FluentButton labeled "Initialize" is located under the header bar.
Padding for Button: The button is aligned to the left with a Container and given left padding of 100 pixels (padding: const EdgeInsets.only(left: 100.0)).
Spacing: A SizedBox(height: 20) is included to give vertical space between the header bar and the button.
Result:
The UI will now display a button labeled "Initialize" positioned 100 pixels from the left-hand edge under the header bar, with some space separating it from the header. You can modify the button's functionality within its onPressed callback as needed! If you have further changes or specific features you'd like to add, let me know!
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
SizedBox(height: 20), // Space between the header and button
// Button placed 100px from the left
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 100.0), // 100px space from the left
child: fluent.Button(
onPressed: () {
// Action for the button
print('Initialize button pressed.');
},
child: const Text('Initialize'), // Button text
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Summary of Key Changes:
Button Definition: The FluentButton was replaced with fluent.Button.
Result:
This code will now properly compile and run, showing an "Initialize" button under the header that is positioned with a 100 pixels margin from the left side. When pressed, this button currently prints a message to the console. You can replace the print statement with any action you want the button to perform.
Make sure you have configured your assets directory correctly and run flutter pub get to fetch any dependencies for the Fluent UI library. If you have further requests or need modifications, feel free to ask!
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
SizedBox(height: 20), // Space between the header and button
// Button placed 100px from the left
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 100.0), // 100px space from the left
child: fluent.Button(
style: ButtonStyle(
padding: ButtonState.all(const EdgeInsets.symmetric(vertical: 15, horizontal: 30)), // Increased padding for size
backgroundColor: ButtonState.all(fluent.Colors.blue), // Optional: customize button color
),
onPressed: () {
// Action for the button
print('Initialize button pressed.');
},
child: const Text('Initialize', style: TextStyle(fontWeight: FontWeight.bold)), // Button text with bold style
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Button Style: The button's padding increases vertically and horizontally for size, making it easier to click and visually larger.
Text Styling: The Text widget inside the button is styled to be bold.
Result:
The "Initialize" button will now be larger and more visible under the header bar, enhancing the usability of your application. You can further customize the appearance of the button, including its background color or even its shape, to better fit your design preferences. If you have any additional changes or features you'd like to incorporate, feel free to ask!
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({Key? key}) : super(key: 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: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: fluent.Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: fluent.Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Fluent UI ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: fluent.ComboBox<String>(
placeholder: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return fluent.ComboBoxItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
SizedBox(height: 20), // Space between the header and button
// Button placed 100px from the left
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 100.0), // 100px space from the left
child: fluent.Button(
style: ButtonStyle(
padding: ButtonState.all(const EdgeInsets.symmetric(vertical: 15, horizontal: 30)), // Increased padding for size
),
onPressed: () {
// Action for the button
print('Initialize button pressed.');
},
child: const Text('Initialize', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)), // Button text with bold style
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [fluent.Colors.white, fluent.Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const fluent.Color(0xFF805306),
mouseOver: const fluent.Color(0xFFF6A00C),
mouseDown: const fluent.Color(0xFF805306),
iconMouseOver: const fluent.Color(0xFF805306),
iconMouseDown: const fluent.Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const fluent.Color(0xFFD32F2F),
mouseDown: const fluent.Color(0xFFB71C1C),
iconNormal: const fluent.Color(0xFF805306),
iconMouseOver: fluent.Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Modifications:
Increased Button Size: The button's padding has been set to EdgeInsets.symmetric(vertical: 15, horizontal: 30) to make it larger. Adjust these values as necessary to create the desired button size.
Bold Text: The text style for the button has been set to use fontWeight: FontWeight.bold, and you can specify a font size to your preference.
Result:
With the updated code, the "Initialize" button will now be larger and visually more prominent, with bold text displayed clearly. If you have any additional tweaks or features that you want to add, feel free to ask!
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
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 = Colors.blue; // Color for the Window Border
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material UI Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: WindowBorder(
color: borderColor,
width: 1,
child: RightSide(), // RightSide widget handles language options
),
),
);
}
}
class RightSide extends StatefulWidget {
const RightSide({Key? key}) : super(key: key);
@override
_RightSideState createState() => _RightSideState();
}
class _RightSideState extends State<RightSide> {
List<String> langOptions = [];
String? selectedLanguage;
@override
void initState() {
super.initState();
fetchLangOptions(); // Fetch language options on startup
}
Future<void> 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<void> 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<void> 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');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Window Title Bar with MoveWindow
WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons(), // Window control buttons
],
),
),
// Header Bar below the Window Title Bar
Container(
height: 40,
color: Colors.black, // Set a color for the header bar to black
child: Row(
children: [
Expanded(
child: Center(
child: Text(
"Text Holder",
style: TextStyle(
color: Colors.white, // Set text color
fontSize: 16, // Set text size
fontWeight: FontWeight.bold, // Set text style
),
),
),
),
// Material ComboBox wrapped in SizedBox to control the width
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add right padding
child: SizedBox(
width: 65, // Set the desired width of the ComboBox
child: DropdownButton<String>(
hint: const Text('..'),
value: selectedLanguage,
onChanged: (String? newValue) {
if (newValue != null) {
setState(() {
selectedLanguage = newValue; // Update selected language
});
// Write the last 2 characters of the selected language to preferences file
updatePreferencesFile(newValue);
}
},
items: langOptions.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
],
),
),
SizedBox(height: 20), // Space between the header and button
// Button placed 100px from the left
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 100.0), // 100px space from the left
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 30),
textStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), // Button text styling
),
onPressed: () {
// Action for the button
print('Initialize button pressed.');
},
child: const Text('Initialize'), // Button text
),
),
// Content Area Below the Header Bar
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.white, Colors.white],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: Text("Content Area"), // Example content
),
),
],
),
),
),
],
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500),
);
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white,
);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
// MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
Key Changes:
Material Button: I replaced the Fluent UI button with an ElevatedButton.
Increased Button Size: The button padding has been increased for height and width, and the text size has been set to 16 pixels with bold styling.
Result:
The "Initialize" button now adopts the Material style, allowing you to have a familiar button look in your application. This button will be larger, and the text will be bold, enhancing visibility and usability. If you have any further questions or need additional modifications, feel free to ask!