Certainly! Let's create a Flutter dashboard that aligns closely with your specifications. We'll ensure that:
- Sidebar and Main Content have distinct background colors.
- Fonts are updated to use "Neue Machina" where required.
- Server Information is positioned accurately.
- Buttons are styled as per your requirements.
- Responsive Layout is maintained while approximating the specified
x and y positions.
Step-by-Step Breakdown:
-
Project Setup:
- Fonts: Ensure that the "Neue Machina" font is added to your project. Place the font files in an
assets/fonts/ directory and update the pubspec.yaml accordingly.
- Assets: Add any icons or images you plan to use.
-
Main Structure:
- Sidebar: A fixed-width container (
w=400) with a distinct background color.
- Main Content: Expands to fill the remaining space with its own background color.
-
Sidebar Components:
- Logo: Positioned at the top with specified padding.
- User Card: Contains the user icon, username, logout button, and balance.
- Navigation Section ("Основное"): Purple-colored text with navigation buttons below.
-
Main Content Components:
- Welcome Card: Positioned with an image, welcome message, and description.
- Server List: Displays a list of servers with detailed information and a management button.
-
Styling Adjustments:
- Colors: Use the specified color codes.
- Buttons: Style the "Управление" button as grey.
- Fonts: Apply "Neue Machina" to the welcome card and server cards.
-
Mock Data: Use hardcoded data for demonstration purposes, which can later be replaced with API calls.
Updated Flutter Code:
import 'package:flutter/material.dart';
void main() {
runApp(NetpcSpaceApp());
}
class NetpcSpaceApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Netpc.Space Dashboard',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Color(0xFF532E41),
scaffoldBackgroundColor: Color(0xFF09090A),
fontFamily: 'Roboto', // Default font
textTheme: TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
),
home: DashboardScreen(),
);
}
}
class DashboardScreen extends StatefulWidget {
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
String selectedTab = 'Главное';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
Sidebar(
selectedTab: selectedTab,
onTabSelected: (tab) {
setState(() {
selectedTab = tab;
});
},
),
Expanded(
child: MainContent(
selectedTab: selectedTab,
),
),
],
),
);
}
}
class Sidebar extends StatelessWidget {
final String selectedTab;
final Function(String) onTabSelected;
Sidebar({required this.selectedTab, required this.onTabSelected});
@override
Widget build(BuildContext context) {
return Container(
width: 400,
height: MediaQuery.of(context).size.height,
color: Color(0xFF1C1C1C), // Distinct sidebar color
padding: EdgeInsets.only(left: 128, top: 63),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Logo
Text(
'netpc.space',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
fontFamily: 'Neue Machina', // Using Neue Machina
),
),
SizedBox(height: 40), // Spacing between logo and user card
// User Card with Balance and Logout
Container(
padding: EdgeInsets.all(16),
width: 400 - 64, // Adjusting for left padding
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
border: Border.all(color: Colors.white30),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
// Static User Icon
Icon(
Icons.person,
color: Colors.white,
size: 40,
),
SizedBox(width: 16),
// Username and Logout IconButton
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'username',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontFamily: 'Neue Machina',
),
),
// Logout Button with Only Icon
Align(
alignment: Alignment.centerLeft,
child: IconButton(
onPressed: () {
// Handle logout
},
icon: Icon(
Icons.logout,
color: Colors.white,
size: 20,
),
tooltip: 'Logout',
),
),
],
),
),
],
),
SizedBox(height: 16),
// User Balance
Text(
'Balance: 10000',
style: TextStyle(
color: Colors.white70,
fontSize: 16,
fontFamily: 'Roboto',
),
),
],
),
),
SizedBox(height: 40), // Spacing between user card and sections
// Основное Section
Padding(
padding: const EdgeInsets.only(left: 0.0),
child: Text(
'Основное',
style: TextStyle(
color: Color(0xFF532E41), // Purple color
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto',
),
),
),
SizedBox(height: 16),
// Navigation Buttons
NavButton(
icon: Icons.dashboard,
label: 'Главное',
isSelected: selectedTab == 'Главное',
onTap: () => onTabSelected('Главное'),
),
NavButton(
icon: Icons.settings,
label: 'Настройки',
isSelected: selectedTab == 'Настройки',
onTap: () => onTabSelected('Настройки'),
),
// Add more navigation buttons here as needed
],
),
);
}
}
class NavButton extends StatelessWidget {
final IconData icon;
final String label;
final bool isSelected;
final VoidCallback onTap;
NavButton({
required this.icon,
required this.label,
this.isSelected = false,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
margin: EdgeInsets.only(bottom: 16),
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: BoxDecoration(
color: isSelected ? Colors.white24 : Colors.transparent,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(
icon,
color: Colors.white,
),
SizedBox(width: 16),
Text(
label,
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'Roboto',
),
),
],
),
),
);
}
}
class MainContent extends StatelessWidget {
final String selectedTab;
MainContent({required this.selectedTab});
@override
Widget build(BuildContext context) {
if (selectedTab == 'Главное') {
return MainTab();
} else if (selectedTab == 'Настройки') {
return SettingsTab();
}
// Add more tabs as needed
return Center(
child: Text(
'Unknown Tab',
style: TextStyle(fontSize: 24, color: Colors.white),
),
);
}
}
class SettingsTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Placeholder for Settings
return Center(
child: Text(
'Настройки',
style: TextStyle(
fontSize: 24,
color: Colors.white,
fontFamily: 'Roboto',
),
),
);
}
}
class MainTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(left: 523 - 400 + 24, top: 74, right: 32, bottom: 50),
// The left padding ensures the main content starts after the sidebar plus some margin
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Welcome Image and Text
Container(
width: 1176,
height: 184,
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: BorderRadius.circular(12),
image: DecorationImage(
image: NetworkImage(
'https://via.placeholder.com/1176x184.png?text=Welcome+Image'), // Placeholder image
fit: BoxFit.cover,
colorFilter:
ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop),
),
),
child: Stack(
children: [
Positioned(
left: 50, // Adjusted for better alignment
top: 20,
child: Text(
'Добро пожаловать, username',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
backgroundColor: Colors.black45,
fontFamily: 'Neue Machina', // Using Neue Machina
),
),
),
Positioned(
left: 50,
top: 60,
child: Container(
width: 800,
child: Text(
'Приветствуем в панели хостинга netpc.space, тут вы можете управлять вашими услугами',
style: TextStyle(
color: Colors.grey[300],
fontSize: 16,
fontFamily: 'Roboto',
),
),
),
),
],
),
),
SizedBox(height: 50),
// Server List
ServerList(),
],
),
),
);
}
}
class ServerList extends StatelessWidget {
// Mock server data
final List<Map<String, String>> servers = [
{
'name': 'Server One',
'address': '192.168.1.1',
'cpu': '4 cores',
'ram': '16GB',
'disk': '512GB SSD',
'flag': '🇩🇪', // Germany flag as emoji
},
{
'name': 'Server Two',
'address': '192.168.1.2',
'cpu': '8 cores',
'ram': '32GB',
'disk': '1TB SSD',
'flag': '🇺🇸', // USA flag as emoji
},
// Add more servers as needed
];
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'My Servers',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto',
),
),
SizedBox(height: 16),
...servers.map((server) => ServerCard(server: server)).toList(),
],
);
}
}
class ServerCard extends StatelessWidget {
final Map<String, String> server;
ServerCard({required this.server});
@override
Widget build(BuildContext context) {
return Container(
width: 1176,
height: 139,
margin: EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.05),
border: Border.all(color: Colors.white30),
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: EdgeInsets.fromLTRB(50, 16, 50, 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Flag
Text(
server['flag'] ?? '',
style: TextStyle(fontSize: 34),
),
SizedBox(width: 16),
// Server Details
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
server['name'] ?? 'Unnamed Server',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontFamily: 'Neue Machina', // Using Neue Machina
),
),
SizedBox(height: 8),
Text(
'Address: ${server['address'] ?? 'N/A'}',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Roboto',
),
),
SizedBox(height: 16),
Row(
children: [
InfoButton(label: 'CPU: ${server['cpu'] ?? 'N/A'}'),
SizedBox(width: 8),
InfoButton(label: 'RAM: ${server['ram'] ?? 'N/A'}'),
SizedBox(width: 8),
InfoButton(label: 'Disk: ${server['disk'] ?? 'N/A'}'),
],
),
],
),
Spacer(),
// Server Info Buttons Positioned to the Right
Row(
children: [
// CPU Info
SizedBox(
width: 132,
height: 37,
child: InfoButton(label: 'CPU: ${server['cpu'] ?? 'N/A'}'),
),
SizedBox(width: 8),
// RAM Info
SizedBox(
width: 132,
height: 37,
child: InfoButton(label: 'RAM: ${server['ram'] ?? 'N/A'}'),
),
SizedBox(width: 8),
// Disk Info
SizedBox(
width: 132,
height: 37,
child: InfoButton(label: 'Disk: ${server['disk'] ?? 'N/A'}'),
),
],
),
SizedBox(width: 16),
// Manage Button
ElevatedButton.icon(
onPressed: () {
// Handle management action
},
icon: Icon(
Icons.settings,
color: Color(0xFF532E41),
size: 20,
),
label: Text(
'Управление',
style: TextStyle(color: Colors.black, fontFamily: 'Roboto'),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey, // Grey background
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
);
}
}
class InfoButton extends StatelessWidget {
final String label;
InfoButton({required this.label});
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {
// OnClick info is zero as per specification
},
child: Text(
label,
style: TextStyle(
fontSize: 14,
fontFamily: 'Roboto',
),
),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.grey.withOpacity(0.5), // Grey with transparency
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 0,
),
);
}
}
Key Points and Adjustments:
-
Font Setup:
-
Sidebar and Main Content Colors:
- Sidebar: Set to
Color(0xFF1C1C1C) for distinction.
- Main Content: Inherits
scaffoldBackgroundColor as Color(0xFF09090A).
-
Positioning:
- While Flutter emphasizes responsive layouts over fixed
x and y positions, padding and alignment are adjusted to approximate the desired layout.
- Welcome Card: Positioned with padding to mimic the
x and y coordinates.
-
Buttons:
- Навигационные Кнопки: Change background on selection.
- Управление Button: Styled as grey with a black color filter.
-
Server Info Buttons:
- Positioned to the right using a combination of
Spacer and adjusted SizedBox widths.
- Each info button has a fixed width and height to match specifications.
-
Responsive Adjustments:
- Used
SizedBox and Spacer to create gaps and align elements appropriately.
- Main Content Padding: Adjusted to account for sidebar width and desired margins.
-
Mock Data:
- Included two servers as examples. You can expand this list or fetch from an API as needed.
-
Color Filters:
- Applied a semi-transparent overlay on the welcome image to enhance text readability.
Next Steps:
-
API Integration:
- Replace mock server data with actual API calls to fetch user and server information.
- Use packages like
http or dio for making HTTP requests.
-
Interactivity:
- Implement functionality for buttons such as logout, navigating between tabs, and managing servers.
-
Enhancements:
- Add animations or transitions for a smoother user experience.
- Implement responsive design for different screen sizes.
-
Testing:
- Test the UI on multiple devices to ensure consistency and responsiveness.
Feel free to customize further based on your specific requirements. Let me know if you need any more assistance or specific features added!