Skip to content

Commit

Permalink
Merge pull request #32 from guchengxi1994/master
Browse files Browse the repository at this point in the history
bump flutter version
  • Loading branch information
guchengxi1994 authored May 15, 2024
2 parents 0604030 + 661bffd commit 359dd7a
Show file tree
Hide file tree
Showing 40 changed files with 3,315 additions and 289 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.19.5
flutter-version: 3.22.0

- name: Cache pubspec
id: cache-pubspec
Expand All @@ -40,6 +40,8 @@ jobs:
- name: install dependencies
run: |
sudo wget -qO /etc/apt/trusted.gpg.d/dart_linux_signing_key.asc https://dl-ssl.google.com/linux/linux_signing_key.pub
sudo apt-get update
sudo apt-get install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev -y
chmod +x /home/runner/work/all_in_one/all_in_one/rust_builder/cargokit/run_build_tool.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.19.5
flutter-version: 3.22.0

- name: Cache pubspec
id: cache-pubspec
Expand Down
3 changes: 3 additions & 0 deletions lib/llm/plugins/chat_db/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'your_database_name';
242 changes: 242 additions & 0 deletions lib/llm/plugins/chat_db/add_db_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import 'package:all_in_one/styles/app_style.dart';
import 'package:flutter/material.dart';
import 'package:all_in_one/src/rust/llm/plugins/chat_db.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'db_notifier.dart';

class AddDbDialog extends ConsumerStatefulWidget {
const AddDbDialog({super.key});

@override
ConsumerState<AddDbDialog> createState() => _AddDbDialogState();
}

class _AddDbDialogState extends ConsumerState<AddDbDialog> {
final _formKey = GlobalKey<FormState>();

/// 这里缺少db类型,不过暂时只支持mysql
// final DatabaseType dbType = DatabaseType.mysql;
final TextEditingController dbNameController = TextEditingController();
final dbNameNode = FocusNode();
final TextEditingController dbAddressController = TextEditingController();
final dbAddressNode = FocusNode();
final TextEditingController dbPortController = TextEditingController();
final dbPortNode = FocusNode();
final TextEditingController dbUsernameController = TextEditingController();
final dbUsernameNode = FocusNode();
final TextEditingController dbPasswordController = TextEditingController();
final dbPasswordNode = FocusNode();
final TextEditingController dbDatabaseController = TextEditingController();
final dbDatabaseNode = FocusNode();

@override
void dispose() {
super.dispose();
dbAddressController.dispose();
dbPortController.dispose();
dbUsernameController.dispose();
dbPasswordController.dispose();
dbDatabaseController.dispose();
dbNameController.dispose();
dbNameNode.dispose();
dbAddressNode.dispose();
dbDatabaseNode.dispose();
dbPortNode.dispose();
dbUsernameNode.dispose();
dbPasswordNode.dispose();
}

final Color textColor = Colors.black;
@override
Widget build(BuildContext context) {
return Material(
borderRadius: BorderRadius.circular(10),
child: Container(
padding: const EdgeInsets.all(10),
width: 300,
height: 350,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: Form(
key: _formKey,
child: Column(
children: [
const SizedBox(
height: 10,
),
_wrapper(
"connect name",
TextFormField(
validator: (value) {
if (value == null || value == "") {
return "";
}
return null;
},
controller: dbNameController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: true,
onFieldSubmitted: (value) {
dbAddressNode.requestFocus();
},
)),
const SizedBox(
height: 10,
),
_wrapper(
"address",
TextFormField(
validator: (value) {
if (value == null || value == "") {
return "";
}
return null;
},
controller: dbAddressController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: false,
onFieldSubmitted: (value) {
dbPortNode.requestFocus();
},
)),
const SizedBox(
height: 10,
),
_wrapper(
"port",
TextFormField(
validator: (value) {
if (value == null ||
value == "" ||
int.tryParse(value) == null) {
return "";
}
return null;
},
controller: dbPortController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: false,
onFieldSubmitted: (value) {
dbUsernameNode.requestFocus();
},
)),
const SizedBox(
height: 10,
),
_wrapper(
"username",
TextFormField(
validator: (value) {
if (value == null || value == "") {
return "";
}
return null;
},
controller: dbUsernameController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: false,
onFieldSubmitted: (value) {
dbPasswordNode.requestFocus();
},
)),
const SizedBox(
height: 10,
),
_wrapper(
"password",
TextFormField(
validator: (value) {
if (value == null || value == "") {
return "";
}
return null;
},
controller: dbPasswordController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: false,
onFieldSubmitted: (value) {
dbDatabaseNode.requestFocus();
},
)),
const SizedBox(
height: 10,
),
_wrapper(
"db name",
TextFormField(
validator: (value) {
if (value == null || value == "") {
return "";
}
return null;
},
controller: dbDatabaseController,
style: TextStyle(color: textColor, fontSize: 12),
decoration: AppStyle.inputDecoration,
autofocus: false,
onFieldSubmitted: (value) {
_submit();
},
)),
const SizedBox(
height: 10,
),
Row(
children: [
const Expanded(child: SizedBox()),
ElevatedButton(
onPressed: () {
_submit();
},
child: const Text("OK"))
],
)
],
)),
),
);
}

_submit() {
if (!_formKey.currentState!.validate()) {
return;
}

DatabaseInfo databaseInfo = DatabaseInfo(
name: dbNameController.text,
address: dbAddressController.text,
port: dbPortController.text,
username: dbUsernameController.text,
password: dbPasswordController.text,
database: dbDatabaseController.text);
ref.read(dbNotifierProvider.notifier).addDatasource(databaseInfo);
Navigator.of(context).pop();
}

_wrapper(String title, Widget child) {
return SizedBox(
height: 35,
child: Row(
children: [
SizedBox(
width: 100,
child: Text(title),
),
Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: child,
))
],
),
);
}
}
24 changes: 24 additions & 0 deletions lib/llm/plugins/chat_db/db_notifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:all_in_one/src/rust/llm/plugins/chat_db.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class DbNotifierState {
final Set<DatabaseInfo> info;

DbNotifierState({
required this.info,
});
}

class DbNotifier extends Notifier<DbNotifierState> {
@override
DbNotifierState build() {
return DbNotifierState(info: {});
}

addDatasource(DatabaseInfo info) {
state = DbNotifierState(info: {...state.info, info});
}
}

final dbNotifierProvider =
NotifierProvider<DbNotifier, DbNotifierState>(() => DbNotifier());
Loading

0 comments on commit 359dd7a

Please sign in to comment.