diff --git a/lib/config.dart b/lib/config.dart new file mode 100644 index 0000000..0eeeacc --- /dev/null +++ b/lib/config.dart @@ -0,0 +1,5 @@ +library config.globals; + +import 'package:allsql/global.dart'; + +MyTheme currentTheme = MyTheme(); diff --git a/lib/global.dart b/lib/global.dart new file mode 100644 index 0000000..9a848ae --- /dev/null +++ b/lib/global.dart @@ -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(); + } +} diff --git a/lib/main.dart b/lib/main.dart index 530df2e..078854d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 createState() => _AllSqlAppState(); +} + +class _AllSqlAppState extends State { + @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, ), diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 91b9422..a333d01 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -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 { @@ -46,9 +48,24 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( + // backgroundColor: appBar: AppBar( centerTitle: true, title: const Text('AllSQL'), + actions: [ + 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), @@ -57,8 +74,16 @@ class _HomePageState extends State { 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), @@ -151,7 +176,13 @@ class _HomePageState extends State { 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; @@ -159,7 +190,13 @@ class _HomePageState extends State { 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; @@ -168,19 +205,40 @@ class _HomePageState extends State { 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(), ); @@ -194,7 +252,12 @@ class _HomePageState extends State { final int rowsUpdated = await db.rawUpdate(_commandController.text); setState(() { - _output = Text('$rowsUpdated rows deleted!'); + _output = Text( + '$rowsUpdated rows updated!', + // style: TextStyle( + // color: + // ), + ); }); break; @@ -202,7 +265,12 @@ class _HomePageState extends State { final int rowsDeleted = await db.rawDelete(_commandController.text); setState(() { - _output = Text('$rowsDeleted rows deleted!'); + _output = Text( + '$rowsDeleted rows deleted!', + // style: TextStyle( + // color: + // ), + ); }); break; @@ -236,7 +304,7 @@ class _HomePageState extends State { color: Colors.grey.shade300, borderRadius: BorderRadius.circular(15.0), ), - child: Text( + child: SelectableText( _descriptions[_commandType] ?? 'Error!', style: TextStyle( color: Colors.grey.shade600, @@ -246,7 +314,10 @@ class _HomePageState extends State { 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, diff --git a/lib/widgets/radio_button.dart b/lib/widgets/radio_button.dart index f58c672..898e1f1 100644 --- a/lib/widgets/radio_button.dart +++ b/lib/widgets/radio_button.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import '../global.dart'; + class RadioButton extends StatelessWidget { final String value; final String groupValue; @@ -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, + // ), + ), ), ], ); diff --git a/pubspec.lock b/pubspec.lock index 814ecd6..4d2dfa1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: