Skip to content

Darktheme thememode #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library config.globals;

import 'package:allsql/global.dart';

MyTheme currentTheme = MyTheme();
15 changes: 15 additions & 0 deletions lib/global.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyTheme with ChangeNotifier {
static bool _isDark = true;

ThemeMode currentTheme() {
return _isDark ? ThemeMode.dark : ThemeMode.light;
}

void switchTheme() {
_isDark = !_isDark;
notifyListeners();
}
}
22 changes: 21 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import 'package:allsql/config.dart';
import 'package:flutter/material.dart';

import 'global.dart';
import 'pages/home_page.dart';

void main() {
runApp(AllSqlApp());
}

class AllSqlApp extends StatelessWidget {
class AllSqlApp extends StatefulWidget {
@override
State<AllSqlApp> createState() => _AllSqlAppState();
}

class _AllSqlAppState extends State<AllSqlApp> {
@override
void initState() {
super.initState();
currentTheme.addListener(() {
setState(() {});
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AllSQL',
darkTheme: ThemeData(
primarySwatch: Colors.teal,
brightness: Brightness.dark,
),
themeMode: currentTheme.currentTheme(),
theme: ThemeData(
primarySwatch: Colors.teal,
),
Expand Down
91 changes: 81 additions & 10 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:allsql/config.dart';
import 'package:flutter/material.dart';
import 'package:sqflite_common/sqlite_api.dart' as sqflite;
import 'package:sqflite_web/sqflite_web.dart';

import '../global.dart';
import '../widgets/radio_button.dart';

class HomePage extends StatefulWidget {
Expand Down Expand Up @@ -46,9 +48,24 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
// backgroundColor:
appBar: AppBar(
centerTitle: true,
title: const Text('AllSQL'),
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 250,
child: IconButton(
icon: const Icon(Icons.light_mode_outlined),
onPressed: () {
currentTheme.switchTheme();
},
),
),
),
],
),
body: ListView(
padding: const EdgeInsets.all(50.0),
Expand All @@ -57,8 +74,16 @@ class _HomePageState extends State<HomePage> {
controller: _commandController,
minLines: 4,
maxLines: 10,
style: const TextStyle(
fontSize: 18.0,
// color:
),
decoration: const InputDecoration(
hintText: 'Enter your SQL command',
hintStyle: TextStyle(
fontSize: 18.0,
// color:
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(15.0),
Expand Down Expand Up @@ -151,15 +176,27 @@ class _HomePageState extends State<HomePage> {
case 'Execute':
await db.execute(_commandController.text);
setState(() {
_output = const Text('Executed the command');
_output = const Text(
'Query Excecuted',
style: TextStyle(
fontSize: 18.0,
// color:
),
);
});
break;

case 'Insert':
final int lastRow =
await db.rawInsert(_commandController.text);
setState(() {
_output = Text('ID of last row inserted is $lastRow.');
_output = Text(
'ID of last row inserted is $lastRow.',
style: TextStyle(
fontSize: 18.0,
// color:
),
);
});
break;

Expand All @@ -168,19 +205,40 @@ class _HomePageState extends State<HomePage> {
await db.rawQuery(_commandController.text);

if (queryOutput.isEmpty) {
_output = const Text('No output!');
_output = Text(
'No output!',
style: TextStyle(
fontSize: 18.0,
// color:
),
);
} else {
_output = DataTable(
columns: queryOutput.first.keys
.map((e) => DataColumn(
label: Text(e),
label: Text(
e,
style: TextStyle(
fontSize: 18.0,
// color:
// ? Colors.white
// : Colors.black,
),
),
))
.toList(),
rows: queryOutput
.map((e) => DataRow(
cells: queryOutput.first.keys
.map((a) => DataCell(
Text(e[a]?.toString() ?? 'null')))
.map((a) => DataCell(Text(
e[a]?.toString() ?? 'null',
style: TextStyle(
fontSize: 18.0,
// color:
// ? Colors.white
// : Colors.black,
),
)))
.toList()))
.toList(),
);
Expand All @@ -194,15 +252,25 @@ class _HomePageState extends State<HomePage> {
final int rowsUpdated =
await db.rawUpdate(_commandController.text);
setState(() {
_output = Text('$rowsUpdated rows deleted!');
_output = Text(
'$rowsUpdated rows updated!',
// style: TextStyle(
// color:
// ),
);
});
break;

case 'Delete':
final int rowsDeleted =
await db.rawDelete(_commandController.text);
setState(() {
_output = Text('$rowsDeleted rows deleted!');
_output = Text(
'$rowsDeleted rows deleted!',
// style: TextStyle(
// color:
// ),
);
});
break;

Expand Down Expand Up @@ -236,7 +304,7 @@ class _HomePageState extends State<HomePage> {
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(15.0),
),
child: Text(
child: SelectableText(
_descriptions[_commandType] ?? 'Error!',
style: TextStyle(
color: Colors.grey.shade600,
Expand All @@ -246,7 +314,10 @@ class _HomePageState extends State<HomePage> {
const SizedBox(height: 20.0),
Text(
'OUTPUT',
style: Theme.of(context).textTheme.headline6,
// style: TextStyle(
// fontSize: 20.0,
// color:
// ),
),
const SizedBox(height: 20.0),
_output,
Expand Down
10 changes: 9 additions & 1 deletion lib/widgets/radio_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';

import '../global.dart';

class RadioButton extends StatelessWidget {
final String value;
final String groupValue;
Expand Down Expand Up @@ -27,7 +29,13 @@ class RadioButton extends StatelessWidget {
onChanged!(value);
}
},
child: Text(value),
child: Text(
value,
// style: TextStyle(
// fontSize: 16,
// color: isDark ? Colors.white : Colors.black,
// ),
),
),
],
);
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -92,7 +92,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -176,7 +176,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down