near final
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
|
||||
|
||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
||||
import 'package:bus_infotainment/backend/live_information.dart';
|
||||
import 'package:bus_infotainment/backend/modules/commands.dart';
|
||||
import 'package:bus_infotainment/utils/delegates.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:text_scroll/text_scroll.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class pages_Settings extends StatefulWidget {
|
||||
@@ -14,22 +17,87 @@ class pages_Settings extends StatefulWidget {
|
||||
|
||||
class _pages_SettingsState extends State<pages_Settings> {
|
||||
|
||||
late final Widget _loginPage;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
if (!LiveInformation().auth.isAuthenticated()){
|
||||
_loginPage = _LoginPage(
|
||||
onLogin: () {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
_loginPage = Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: ElevatedButton(
|
||||
onPressed: (){
|
||||
setState(() {});
|
||||
LiveInformation().auth.deleteSession();
|
||||
|
||||
},
|
||||
|
||||
// make the corner radius 4, background color match the theme, and text colour white, fill to width of parent
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4)
|
||||
),
|
||||
minimumSize: Size(double.infinity, 48)
|
||||
),
|
||||
|
||||
child: Text(
|
||||
"Sign out",
|
||||
style: GoogleFonts.interTight(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
letterSpacing: 0.5
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
if (LiveInformation().auth.isAuthenticated()){
|
||||
return Container(
|
||||
return Container(
|
||||
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
||||
children: [
|
||||
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
child: Console()
|
||||
),
|
||||
|
||||
Container(
|
||||
height: 2,
|
||||
width: double.infinity,
|
||||
color: Colors.white70,
|
||||
),
|
||||
|
||||
);
|
||||
} else {
|
||||
return _LoginPage(
|
||||
onLogin: () {
|
||||
Container(
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
padding: const EdgeInsets.all(8),
|
||||
|
||||
child: _loginPage,
|
||||
)
|
||||
|
||||
],
|
||||
|
||||
),
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,4 +694,118 @@ class PW_TextField extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Console widget
|
||||
class Console extends StatefulWidget {
|
||||
|
||||
Console({super.key});
|
||||
|
||||
@override
|
||||
State<Console> createState() => _ConsoleState();
|
||||
}
|
||||
|
||||
class _ConsoleState extends State<Console> {
|
||||
|
||||
ListenerReceipt? _listenerReceipt;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
_listenerReceipt = LiveInformation().commandModule.onCommandReceived.addListener((p0) {
|
||||
print("Command received, updating console");
|
||||
|
||||
setState(() {});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
List<Widget> commands = [];
|
||||
|
||||
TextEditingController commandController = TextEditingController();
|
||||
|
||||
commands.add(
|
||||
Text("Command History:")
|
||||
);
|
||||
|
||||
for (int i = 0; i < LiveInformation().commandModule.commandHistory.length; i++){
|
||||
CommandInfo command = LiveInformation().commandModule.commandHistory[i];
|
||||
|
||||
commands.add(
|
||||
TextScroll(
|
||||
command.command,
|
||||
style: GoogleFonts.teko(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey.shade300,
|
||||
letterSpacing: 0.1,
|
||||
),
|
||||
mode: TextScrollMode.bouncing,
|
||||
pauseBetween: const Duration(seconds: 2),
|
||||
pauseOnBounce: const Duration(seconds: 1),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white70, width: 2),
|
||||
color: Colors.black,
|
||||
),
|
||||
|
||||
child: Column(
|
||||
|
||||
children: [
|
||||
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
|
||||
height: 300,
|
||||
|
||||
child: ListView(
|
||||
children: commands,
|
||||
),
|
||||
),
|
||||
|
||||
Container(
|
||||
height: 2,
|
||||
width: double.infinity,
|
||||
color: Colors.white70,
|
||||
),
|
||||
|
||||
Container(
|
||||
height: 50,
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: TextField(
|
||||
controller: commandController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: ">",
|
||||
),
|
||||
style: GoogleFonts.teko(
|
||||
height: 1,
|
||||
),
|
||||
onSubmitted: (value) {
|
||||
commandController.clear();
|
||||
LiveInformation().commandModule.executeCommand(value);
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
],
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user