Skip to content
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

added darktheme #18

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions lib/global.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool isDark = true;
28 changes: 28 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
import 'package:flutter/material.dart';

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

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

class AllSqlApp extends StatelessWidget {
MaterialColor buildMaterialColor(Color color) {
final List<double> strengths = <double>[.05];
final Map<int, Color> swatch = <int, Color>{};
final int r = color.red;
final int g = color.green;
final int b = color.blue;

for (int i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
for (final strength in strengths) {
final double ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
1,
);
}
return MaterialColor(color.value, swatch);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AllSQL',
theme: ThemeData(
primarySwatch: Colors.teal,
textTheme: TextTheme(
headline6: TextStyle(
color: isDark ? Colors.white : Colors.black,
),
),
),
home: const HomePage(),
);
Expand Down
108 changes: 96 additions & 12 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:allsql/global.dart';
import 'package:flutter/material.dart';
import 'package:sqflite_common/sqlite_api.dart' as sqflite;
import 'package:sqflite_web/sqflite_web.dart';
Expand Down Expand Up @@ -46,9 +47,39 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: isDark ? const Color(0xFF463838) : Colors.white,
appBar: AppBar(
centerTitle: true,
title: const Text('AllSQL'),
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 250,
child: ListTile(
title: const Text(
'Dark Theme',
style: TextStyle(
fontSize: 17.0,
color: Colors.white,
fontWeight: FontWeight.normal),
),
leading: Icon(
Icons.brightness_6,
color: isDark ? Colors.white : Colors.black,
),
trailing: Switch(
activeColor: Colors.white,
value: isDark,
onChanged: (value) {
setState(() {
isDark = !isDark;
});
}),
),
),
),
],
),
body: ListView(
padding: const EdgeInsets.all(50.0),
Expand All @@ -57,10 +88,17 @@ class _HomePageState extends State<HomePage> {
controller: _commandController,
minLines: 4,
maxLines: 10,
decoration: const InputDecoration(
style: TextStyle(
fontSize: 18.0, color: isDark ? Colors.white : Colors.black),
decoration: InputDecoration(
hintText: 'Enter your SQL command',
hintStyle: TextStyle(
fontSize: 18.0, color: isDark ? Colors.white : Colors.black),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
borderSide: BorderSide(
color: isDark ? const Color(0xff0665B1) : Colors.teal,
),
borderRadius: const BorderRadius.all(
Radius.circular(15.0),
),
),
Expand Down Expand Up @@ -151,15 +189,27 @@ class _HomePageState extends State<HomePage> {
case 'Execute':
await db.execute(_commandController.text);
setState(() {
_output = const Text('Executed the command');
_output = Text(
'Query Excecuted',
style: TextStyle(
fontSize: 18.0,
color: isDark ? Colors.white : Colors.black,
),
);
});
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: isDark ? Colors.white : Colors.black,
),
);
});
break;

Expand All @@ -168,19 +218,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: isDark ? Colors.white : Colors.black,
),
);
} else {
_output = DataTable(
columns: queryOutput.first.keys
.map((e) => DataColumn(
label: Text(e),
label: Text(
e,
style: TextStyle(
fontSize: 18.0,
color: isDark
? 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: isDark
? Colors.white
: Colors.black,
),
)))
.toList()))
.toList(),
);
Expand All @@ -194,15 +265,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: isDark ? Colors.white : Colors.black,
),
);
});
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: isDark ? Colors.white : Colors.black,
),
);
});
break;

Expand Down Expand Up @@ -236,7 +317,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 +327,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: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 20.0),
_output,
Expand Down
6 changes: 5 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,9 @@ 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