Skip to content

Commit

Permalink
Added ThemeMode on SigaPage
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusrmatias committed Nov 20, 2023
1 parent d638d9a commit d11df87
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 19 deletions.
96 changes: 78 additions & 18 deletions lib/src/pages/siga_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,102 @@ class _SigaPageState extends State<SigaPage> {
..loadRequest(Uri.parse('https://siga.cps.sp.gov.br/aluno/login.aspx'))
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(MainTheme.white);
Brightness? currentTheme;
@override
void initState() {
// TODO: implement initState
super.initState();
controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (e)async{
if(e=='https://siga.cps.sp.gov.br/aluno/login.aspx'){
student = await control.queryStudent();
await controller.runJavaScript("document.getElementById('vSIS_USUARIOID').value='${student.cpf}'");
await controller.runJavaScript("document.getElementById('vSIS_USUARIOSENHA').value='${student.password}'");
await controller.runJavaScript("document.getElementsByName('BTCONFIRMA')[0].click()");
}
}
));
controller
.setNavigationDelegate(NavigationDelegate(onPageFinished: (e) async {
if (e == 'https://siga.cps.sp.gov.br/aluno/login.aspx') {
currentTheme = Theme.of(context).brightness;
student = await control.queryStudent();
await controller.runJavaScript(
"document.getElementById('vSIS_USUARIOID').value='${student.cpf}'");
await controller.runJavaScript(
"document.getElementById('vSIS_USUARIOSENHA').value='${student.password}'");
await controller.runJavaScript(
"document.getElementsByName('BTCONFIRMA')[0].click()");
}
_alterTheme();
}));
}

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
title: const Text('SIGA', style: TextStyle(fontWeight: FontWeight.bold)),
title:
const Text('SIGA', style: TextStyle(fontWeight: FontWeight.bold)),
centerTitle: true,
actions: [
IconButton(
onPressed: () => _alterTheme(alterTheme: true),
icon: const Icon(Icons.brightness_4))
],
),
body: WebViewWidget(controller: controller),
bottomNavigationBar: Container(
color: Theme.of(context).colorScheme.primary,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(onPressed: ()async{await controller.goBack();}, icon: const Icon(Icons.arrow_back)),
IconButton(onPressed: (){controller.loadRequest(Uri.parse('https://siga.cps.sp.gov.br/aluno/home.aspx'));}, icon: const Icon(Icons.home)),
IconButton(onPressed: ()async{await controller.goForward();}, icon: const Icon(Icons.arrow_forward)),
IconButton(
onPressed: () async {
await controller.goBack();
},
icon: const Icon(Icons.arrow_back)),
IconButton(
onPressed: () {
controller.loadRequest(Uri.parse(
'https://siga.cps.sp.gov.br/aluno/home.aspx'));
},
icon: const Icon(Icons.home)),
IconButton(
onPressed: () async {
await controller.goForward();
},
icon: const Icon(Icons.arrow_forward)),
],
),
)
);
));
}
}

_alterTheme({bool alterTheme = false}) async {
if (alterTheme)
currentTheme =
currentTheme == Brightness.dark ? Brightness.light : Brightness.dark;
if (currentTheme == Brightness.dark) {
await controller.runJavaScript('''
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
elements[i].style.backgroundColor = "#252525";
}
''');
await controller.runJavaScript('''
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
elements[i].style.color = "White";
}
''');
} else {
await controller.runJavaScript('''
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
elements[i].style.backgroundColor = "White";
}
''');
await controller.runJavaScript('''
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
elements[i].style.color = "Black";
}
''');
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 2.5.1+43
version: 2.5.1+44

environment:
sdk: '>=3.0.5 <4.0.0'
Expand Down

0 comments on commit d11df87

Please sign in to comment.