Untitled
import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:window_size/window_size.dart'; import 'package:flutter/services.dart'; import 'package:flutter_highlight/flutter_highlight.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:file_picker/file_picker.dart'; import 'dart:io'; import 'package:provider/provider.dart'; import 'package:python_shell/python_shell.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); setWindowSize(); runApp(const Home()); } void setWindowSize() { const Size minSize = Size(800, 800); setWindowMinSize(minSize); } class MyApp extends StatefulWidget { final String? fileContent; final String? filePath; const MyApp({super.key, this.fileContent, this.filePath}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { FocusNode focusNode = FocusNode(); bool _isHoverd = false; bool _isVisible = false; String? fileContent; String output = ""; String? filePatha; late PythonShell pythonShell; void initState() { super.initState(); fileContent ??= widget.fileContent; pythonShell = PythonShell(PythonShellConfig()); } void onContentLoaded(String content, String path) { setState(() { fileContent = content; // Update the file content filePatha = path; // Store the file path if needed }); } Future<void> runPythonCode(String code) async { try { var shell = PythonShell(PythonShellConfig()); await shell.initialize(); shell.runString( code, listener: ShellListener( onMessage: (message) { // Capture messages (output from Python code) setState(() { output = message; // Update `output` with the received message }); }, onError: (e, s) { // Handle errors setState(() { output = "Error: $e"; }); }, onComplete: () { // Optionally handle completion print("Python script execution completed!"); }, ), ); } catch (e) { setState(() { output = "Initialization Error: $e"; }); } } late TextEditingController _controller = TextEditingController(text: fileContent ?? ''); @override void _toggleContainer() { setState(() { _isVisible = !_isVisible; }); } @override Widget build(BuildContext context) { Pythona(onContentLoaded: (content, path) { setState(() { fileContent = content; }); }); Pythona( onContentLoaded: (filePath, content) { setState(() { filePatha = filePath; }); }, ); print(filePatha); void _handleSave(String Filepathb, String newstuff) async { File file = File(Filepathb); setState(() { fileContent = _controller.text; print('object'); }); await file.writeAsString(newstuff); print('it saved'); if (!file.existsSync()) { print("File does not exist: $Filepathb"); return; } } return MaterialApp( home: Scaffold( backgroundColor: Colors.grey[900], body: Shortcuts( shortcuts: <LogicalKeySet, Intent>{ LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.keyS): SaveIntent(), LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyS): SaveIntent(), }, child: Actions( actions: <Type, Action<Intent>>{ SaveIntent: CallbackAction<SaveIntent>(onInvoke: (intent) { _handleSave(filePatha.toString(), _controller.text); print('rehehehehe'); return null; }), }, child: LayoutBuilder( builder: (context, constraints) { double screenWidth = constraints.maxWidth; double screenHeight = constraints.maxHeight; return Column( children: [ Container( height: screenHeight * 0.05, width: screenWidth, color: Colors.grey[900], child: Row( children: [ Padding( padding: const EdgeInsets.only(left: 30.0), child: TextButton( onPressed: () {}, child: const Text('File'), style: TextButton.styleFrom( foregroundColor: Colors.white, ), ), ), TextButton( onPressed: () { Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => Home(), ), ); }, child: const Text('Home'), style: TextButton.styleFrom( foregroundColor: Colors.white, ), ), TextButton( onPressed: () {}, child: const Text('Edit'), style: TextButton.styleFrom( foregroundColor: Colors.white, ), ), TextButton( onPressed: () {}, child: const Text('Run'), style: TextButton.styleFrom( foregroundColor: Colors.white, ), ), SizedBox( width: screenWidth * 0.4, ), const Text( 'FileName.txt', style: TextStyle(color: Colors.white), ), ], ), ), Padding( padding: const EdgeInsets.only(left: 30.0), child: Row( children: [ MouseRegion( onEnter: (_) => setState(() => _isHoverd = true), onExit: (_) => setState(() => _isHoverd = false), child: AnimatedContainer( duration: const Duration(milliseconds: 300), height: screenHeight * 0.9, width: _isHoverd ? 200 : 100, decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), color: const Color(0xFF2D2D2D), ), child: _isHoverd ? Column( children: [ const Row( children: [ Icon( Icons.bolt, size: 60, color: Colors.yellow, ), Flexible( child: Text( overflow: TextOverflow.ellipsis, 'SIDE', style: TextStyle( fontFamily: 'Pacifico', fontSize: 40, color: Colors.white, ), ), ), ], ), Container( width: screenWidth, height: screenHeight * 0.001, color: Colors.white, ), Padding( padding: const EdgeInsets.only(top: 10.0), child: FittedBox( fit: BoxFit.fill, child: TextButton.icon( icon: const Icon( Icons.dashboard_customize), onPressed: _toggleContainer, label: const Text('Explorer'), style: TextButton.styleFrom( foregroundColor: Colors.white, iconColor: Colors.white, iconSize: 30, textStyle: const TextStyle( color: Colors.white, fontSize: 30, ), ), ), ), ), Padding( padding: const EdgeInsets.only(top: 10.0), child: FittedBox( fit: BoxFit.fill, child: TextButton.icon( icon: const Icon(Icons.home), onPressed: () { Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => Home())); }, label: const Text('Home'), style: TextButton.styleFrom( foregroundColor: Colors.white, iconColor: Colors.white, iconSize: 30, textStyle: const TextStyle( color: Colors.white, fontSize: 30, ), ), ), ), ), Padding( padding: const EdgeInsets.only(top: 10.0), child: FittedBox( fit: BoxFit.fill, child: TextButton.icon( icon: const Icon(Icons.bug_report), onPressed: () {}, label: const Text('Debug'), style: TextButton.styleFrom( foregroundColor: Colors.white, iconColor: Colors.white, iconSize: 30, textStyle: const TextStyle( color: Colors.white, fontSize: 30, ), ), ), ), ), SizedBox( height: screenHeight * 0.60, ), Padding( padding: const EdgeInsets.only(top: 10.0), child: FittedBox( fit: BoxFit.fill, child: TextButton.icon( icon: const Icon(Icons.settings), onPressed: () { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: Colors.grey[800], title: const Text( 'Settings'), contentPadding: const EdgeInsets.all( 300), // Add padding around the content content: SizedBox( width: screenWidth, // Set a fixed width for the dialog child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment .start, children: [ ListTile( leading: const Icon( Icons.book, color: Colors .white, ), title: const Text( 'Quran', style: TextStyle( color: Colors .white, ), ), trailing: Switch( value: true, onChanged: (value) { // Handle Wi-Fi toggle }, ), ), ListTile( leading: const Icon( Icons.book, color: Colors .white, ), title: const Text( 'Font Size', style: TextStyle( color: Colors .white, ), ), trailing: SizedBox( width: screenWidth * 0.05, height: screenHeight * 0.1, child: TextField( decoration: InputDecoration( border: OutlineInputBorder(), ), controller: TextEditingController(), keyboardType: TextInputType .number, inputFormatters: <TextInputFormatter>[ FilteringTextInputFormatter .digitsOnly, LengthLimitingTextInputFormatter( 2), // Optional: Limit input to 2 digits ], onChanged: (value) { int? newValue = int.tryParse( value); if (newValue != null && newValue > 50) { // If value is greater than 50, set it to 50 value = '50'; // Optionally update the controller with the new value if you want it displayed immediately TextEditingController().text = value; } }, ), ), ), ], ), ), ), actions: [ TextButton( onPressed: () { Navigator.of( context) .pop(); // Close the dialog }, child: const Text( 'Close'), ), ], ); }, ); }, label: const Text('Settings'), style: TextButton.styleFrom( foregroundColor: Colors.white, iconColor: Colors.white, iconSize: 30, textStyle: const TextStyle( color: Colors.white, fontSize: 30, ), ), ), ), ), ], ) : Column( children: [ const Icon( Icons.bolt, size: 60, color: Colors.yellow, ), Container( width: screenWidth, height: screenHeight * 0.001, color: Colors.white, ), const Padding( padding: EdgeInsets.only(top: 30.0), child: Icon(Icons.dashboard_customize, size: 30, color: Colors.white), ), const Padding( padding: EdgeInsets.only(top: 10.0), child: Icon(Icons.home, size: 30, color: Colors.white), ), const Padding( padding: EdgeInsets.only(top: 10.0), child: Icon(Icons.bug_report, size: 30, color: Colors.white), ), SizedBox( height: screenHeight * 0.6, ), Icon( Icons.settings, size: 30, color: Colors.white, ), ], ), ), ), Visibility( visible: _isVisible, child: Container( height: screenHeight * 0.9, width: screenWidth * 0.1, color: Colors.grey[800], ), ), Column( children: [ Padding( padding: const EdgeInsets.only(left: 100.0), child: Container( height: screenHeight * 0.75, width: screenWidth * 0.75, color: Colors.grey[800], child: SingleChildScrollView( child: TextField( onChanged: (value) { setState(() { fileContent = value; }); }, controller: _controller, decoration: InputDecoration( border: InputBorder.none, focusedBorder: InputBorder.none, enabledBorder: InputBorder.none, errorBorder: InputBorder.none, disabledBorder: InputBorder.none, hintText: 'Enter your code here', hintStyle: TextStyle( color: Colors.white, ), fillColor: Colors.grey[800], ), style: GoogleFonts.jetBrainsMono( color: Colors.white, ), cursorColor: Colors.white, maxLines: null, ), ), ), ), Padding( padding: const EdgeInsets.only( left: 100.0, top: 30, ), child: Container( height: screenHeight * 0.15, width: screenWidth * 0.75, color: Colors.grey[800], ), ), ], ), ], ), ), ], ); }, ), ), ), ), ); } } class Home extends StatelessWidget { const Home({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: Colors.grey[900], body: LayoutBuilder(builder: (context, constraints) { double screenWidth = constraints.maxWidth; double screenHeight = constraints.maxHeight; return Column( children: [ SizedBox( height: screenHeight * 0.3, ), Center( child: Text( 'Welcome to', style: TextStyle( color: Colors.white, fontSize: 40, ), ), ), Row( mainAxisSize: MainAxisSize.min, children: [ Text( 'SIDE', style: TextStyle( color: Colors.white, fontSize: 100, fontFamily: 'Pacifico', ), ), Icon(Icons.bolt, size: 150, color: Colors.yellow), ], ), Row( children: [ SizedBox( width: screenWidth * 0.4, ), Text( 'Simple Integrated development environment', style: TextStyle(color: Colors.white, fontSize: 15), ), ], ), SizedBox( height: screenHeight * 0.03, ), Row( children: [ SizedBox( width: screenWidth * 0.44, ), FilledButton( onPressed: () { Navigator.push( context, MaterialPageRoute( builder: (context) => Pythona( onContentLoaded: (fileContent, filePath) { Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => MyApp( fileContent: fileContent, filePath: filePath, ), ), ); }, ), ), ); }, child: Text('Python'), style: FilledButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.grey[800], ), ), SizedBox( width: screenWidth * 0.005, ), Text( 'or', style: TextStyle( color: Colors.white, ), ), SizedBox( width: screenWidth * 0.005, ), FilledButton( onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => Kotlin())); }, child: Text('Kotlin'), style: FilledButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.grey[800], ), ), ], ), ], ); }), ), ); } } class SaveIntent extends Intent {} class Pythona extends StatefulWidget { final Function(String, String) onContentLoaded; const Pythona({super.key, required this.onContentLoaded}); @override State<Pythona> createState() => _PythonaState(); } class _PythonaState extends State<Pythona> { String? fileContent; String? filePath; void updateFileContent(String content) { setState(() { fileContent = content; Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => MyApp( fileContent: content, filePath: filePath, ))); }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: Colors.grey[900], body: LayoutBuilder(builder: (context, constraints) { double screenWidth = constraints.maxWidth; double screenHeight = constraints.maxHeight; return Column( children: [ Row( children: [ SizedBox( width: screenWidth * 0.45, ), Center( child: Text( 'Python', style: TextStyle( color: Colors.white, fontSize: 40, ), ), ), Icon( FontAwesome5Brands.python, size: 40, color: Colors.blue, ), ], ), SizedBox( height: screenHeight * 0.1, ), GestureDetector( onTap: () async { // Open file picker with a filter for Python files FilePickerResult? result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['py'], // Only allow .py files ); if (result != null) { // Get the picked file PlatformFile file = result.files.single; // Optionally, read file content (if it's a Python file) if (file.path != null && result.files.single.path != null) { try { String filePath = result.files.single.path!; String fileContent = await File(file.path!).readAsString(); widget.onContentLoaded( fileContent, filePath, ); // Pass content back to parent } catch (e) { print('Error reading file: $e'); } } } else { // Handle when no file is selected print('No Python file selected'); } }, child: Container( decoration: BoxDecoration( color: Colors.grey[800], borderRadius: BorderRadius.circular(20), ), width: screenWidth * 0.7, height: screenHeight * 0.6, child: Column( children: [ SizedBox(height: screenHeight * 0.03), Text( 'Drag and drop file or click to browse', style: GoogleFonts.lexendGiga( fontWeight: FontWeight.bold, color: Colors.white, fontSize: 40, ), ), Icon( Icons.image, color: Colors.white, size: 500, ), ], ), ), ), SizedBox( height: screenHeight * 0.05, ), Text( 'or', style: GoogleFonts.pacifico(color: Colors.white, fontSize: 30), ), SizedBox( height: screenHeight * 0.05, ), FilledButton( onPressed: () { //TODO: Implement Python code execution }, child: Text('Create New'), style: FilledButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.grey[800], ), ) ], ); }), ), ); } } class Kotlin extends StatelessWidget { const Kotlin({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: Colors.grey[900], body: LayoutBuilder(builder: (context, constraints) { double screenWidth = constraints.maxWidth; double screenHeight = constraints.maxHeight; return Column( children: [ Row( children: [ SizedBox( width: screenWidth * 0.45, ), Center( child: Text( 'Kotlin', style: TextStyle( color: Colors.white, fontSize: 40, ), ), ), SizedBox( width: screenWidth * 0.005, ), Image.asset('Assets/Kotlin.png', height: 40), ], ), SizedBox( height: screenHeight * 0.1, ), Container( decoration: BoxDecoration( color: Colors.grey[800], borderRadius: BorderRadius.circular(20), ), width: screenWidth * 0.7, height: screenHeight * 0.6, child: Column( children: [ SizedBox( height: screenHeight * 0.03, ), Text( 'Drag and drop file or click to browse', style: GoogleFonts.lexendGiga( fontWeight: FontWeight.bold, color: Colors.white, fontSize: 40, ), ), Icon( Icons.image, color: Colors.white, size: 500, ), ], ), ), SizedBox( height: screenHeight * 0.05, ), Text( 'or', style: GoogleFonts.pacifico(color: Colors.white, fontSize: 30), ), SizedBox( height: screenHeight * 0.05, ), FilledButton( onPressed: () { //TODO: Implement Python code execution }, child: Text('Create New'), style: FilledButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.grey[800], ), ) ], ); }), ), ); } }
Leave a Comment