Sure! I can help you create a Flutter application based on your specifications. Below is a complete guide along with the complete main.dart code to implement the described application.
Overview
The application will consist of three pages:
-
Welcome Page
- Displays "Добро пожаловать в UNIX" centered on the screen.
- A "Начать" button that navigates to the second page.
-
Selection Page
- Contains three blocks: "Русский", "Математика", "Информатика" each with a toggle switch.
- When a switch is turned on, a slider appears below it allowing values from 1 to 100.
- A "Продолжить" button that navigates to the third page.
-
Development Page
- Displays the text "In development".
The app uses a dark theme with green accents.
Step-by-Step Implementation
1. Setting Up the Flutter Project
First, ensure you have Flutter installed on your system. If not, follow the official Flutter installation guide.
Create a new Flutter project:
flutter create unix_app
Navigate to the project directory:
cd unix_app
2. Updating pubspec.yaml
For this simple application, the default dependencies should suffice. However, if you plan to add more features in the future, you might need to update the dependencies accordingly.
3. Creating the main.dart File
Replace the contents of lib/main.dart with the following code:
import 'package:flutter/material.dart';
void main() {
runApp(UnixApp());
}
class UnixApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'UNIX App',
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.green[700],
scaffoldBackgroundColor: Colors.black,
accentColor: Colors.greenAccent,
buttonTheme: ButtonThemeData(
buttonColor: Colors.green[700],
textTheme: ButtonTextTheme.primary,
),
),
initialRoute: '/',
routes: {
'/': (context) => WelcomePage(),
'/selection': (context) => SelectionPage(),
'/development': (context) => DevelopmentPage(),
},
);
}
}
class WelcomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
// App bar can be omitted or customized as needed
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Добро',
style: TextStyle(fontSize: 32, color: Colors.greenAccent),
),
Text(
'пожаловать',
style: TextStyle(fontSize: 32, color: Colors.greenAccent),
),
Text(
'в',
style: TextStyle(fontSize: 32, color: Colors.greenAccent),
),
Text(
'UNIX',
style: TextStyle(fontSize: 32, color: Colors.greenAccent),
),
SizedBox(height: 40),
ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/selection');
},
child: Text('Начать'),
style: ElevatedButton.styleFrom(
padding:
EdgeInsets.symmetric(horizontal: 50.0, vertical: 15.0),
textStyle: TextStyle(fontSize: 18),
primary: Colors.green[700],
),
),
],
),
),
),
);
}
}
class SelectionPage extends StatefulWidget {
@override
_SelectionPageState createState() => _SelectionPageState();
}
class _SelectionPageState extends State<SelectionPage> {
bool russianSelected = false;
bool mathSelected = false;
bool informaticsSelected = false;
double russianValue = 50;
double mathValue = 50;
double informaticsValue = 50;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Выбор предметов'),
backgroundColor: Colors.green[700],
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
SubjectBlock(
title: 'Русский',
isSelected: russianSelected,
onToggle: (value) {
setState(() {
russianSelected = value;
});
},
sliderValue: russianValue,
onSliderChange: (value) {
setState(() {
russianValue = value;
});
},
),
SizedBox(height: 20),
SubjectBlock(
title: 'Математика',
isSelected: mathSelected,
onToggle: (value) {
setState(() {
mathSelected = value;
});
},
sliderValue: mathValue,
onSliderChange: (value) {
setState(() {
mathValue = value;
});
},
),
SizedBox(height: 20),
SubjectBlock(
title: 'Информатика',
isSelected: informaticsSelected,
onToggle: (value) {
setState(() {
informaticsSelected = value;
});
},
sliderValue: informaticsValue,
onSliderChange: (value) {
setState(() {
informaticsValue = value;
});
},
),
SizedBox(height: 40),
ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/development');
},
child: Text('Продолжить'),
style: ElevatedButton.styleFrom(
padding:
EdgeInsets.symmetric(horizontal: 50.0, vertical: 15.0),
textStyle: TextStyle(fontSize: 18),
primary: Colors.green[700],
),
),
],
),
),
),
);
}
}
class SubjectBlock extends StatelessWidget {
final String title;
final bool isSelected;
final Function(bool) onToggle;
final double sliderValue;
final Function(double) onSliderChange;
SubjectBlock({
required this.title,
required this.isSelected,
required this.onToggle,
required this.sliderValue,
required this.onSliderChange,
});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style:
TextStyle(fontSize: 20, color: Colors.greenAccent),
),
Switch(
value: isSelected,
onChanged: onToggle,
activeColor: Colors.greenAccent,
),
],
),
if (isSelected)
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Slider(
value: sliderValue,
min: 1,
max: 100,
divisions: 99,
label: sliderValue.round().toString(),
activeColor: Colors.greenAccent,
inactiveColor: Colors.green[700],
onChanged: onSliderChange,
),
),
],
);
}
}
class DevelopmentPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
// App bar with a back button
appBar: AppBar(
title: Text('Разработка'),
backgroundColor: Colors.green[700],
),
body: Center(
child: Text(
'In development',
style: TextStyle(fontSize: 24, color: Colors.greenAccent),
),
),
);
}
}
4. Understanding the Code
a. Theme Configuration
The UnixApp class sets up the dark theme with green accents:
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.green[700],
scaffoldBackgroundColor: Colors.black,
accentColor: Colors.greenAccent,
buttonTheme: ButtonThemeData(
buttonColor: Colors.green[700],
textTheme: ButtonTextTheme.primary,
),
),
b. Routing
We use named routes for navigation between pages:
initialRoute: '/',
routes: {
'/': (context) => WelcomePage(),
'/selection': (context) => SelectionPage(),
'/development': (context) => DevelopmentPage(),
},
c. Welcome Page
Displays the welcome text and a "Начать" button:
class WelcomePage extends StatelessWidget {
// ... widget build method
}
d. Selection Page
Contains three SubjectBlock widgets, each representing a subject with a switch and a slider:
class SelectionPage extends StatefulWidget {
// ... widget build method
}
class SubjectBlock extends StatelessWidget {
// ... widget build method
}
Each SubjectBlock takes parameters to manage its state, including whether it's selected and the slider's value.
e. Development Page
A simple page displaying "In development":
class DevelopmentPage extends StatelessWidget {
// ... widget build method
}
5. Running the Application
Ensure you have a device connected or an emulator running. Then, execute:
flutter run
This will compile and run the application on your selected device.
Screenshots
Since I can't provide actual screenshots here, here's a description of what each page will look like:
-
Welcome Page
- Black background with green-accented text "Добро пожаловать в UNIX" centered vertically.
- A green "Начать" button below the text.
-
Selection Page
- App bar titled "Выбор предметов".
- Three rows each with the subject name and a switch.
- When a switch is turned on, a slider appears below the subject.
- A green "Продолжить" button at the bottom.
-
Development Page
- App bar titled "Разработка".
- Centered text "In development" in green.
Customizations and Enhancements
-
State Management: For larger applications, consider using state management solutions like Provider, Bloc, or Riverpod.
-
Persisting Data: If you need to save user selections, you can integrate packages like shared_preferences or use local databases.
-
Responsive Design: Ensure the app looks good on various screen sizes by testing on different devices or using responsive design techniques.
-
Localization: Since you're using Russian text, you might want to set up Flutter's localization features for better scalability.
Conclusion
This Flutter application meets your specifications with a dark theme and green accents. It includes three pages with the required functionalities. Feel free to modify and enhance the application as per your needs. If you encounter any issues or have further questions, feel free to ask!