Commit b99145b8 authored by netyouli's avatar netyouli

添加创作增删改查功能

parent 2ed6da52
...@@ -501,7 +501,7 @@ ...@@ -501,7 +501,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/RunnerDebug.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/RunnerDebug.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
...@@ -518,7 +518,7 @@ ...@@ -518,7 +518,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wudi.app; PRODUCT_BUNDLE_IDENTIFIER = com.wudi.app;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "iOS Team Store Provisioning Profile: com.wudi.app"; "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "dev-profile";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
...@@ -550,7 +550,7 @@ ...@@ -550,7 +550,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wudi.app; PRODUCT_BUNDLE_IDENTIFIER = com.wudi.app;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "iOS Team Store Provisioning Profile: com.wudi.app"; "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "dis-profile";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
......
...@@ -19,6 +19,7 @@ class AppRoutes { ...@@ -19,6 +19,7 @@ class AppRoutes {
static const HOME_PAGE = '/home'; static const HOME_PAGE = '/home';
static const CREATION_PAGE = '/creation'; static const CREATION_PAGE = '/creation';
static const CREATION_HISTORY_PAGE = '/creation-history'; static const CREATION_HISTORY_PAGE = '/creation-history';
static const CREATION_HISTORY_DETAIL_PAGE = '/creation-history-detail';
static const CREATION_PAGE_DETAIL = '/creation-detail'; static const CREATION_PAGE_DETAIL = '/creation-detail';
static const ASSISTANT_PAGE = '/assistant'; static const ASSISTANT_PAGE = '/assistant';
static const MY_PAGE = '/my'; static const MY_PAGE = '/my';
......
...@@ -2,6 +2,7 @@ import 'package:chart/pages/assistant-item/index.dart'; ...@@ -2,6 +2,7 @@ import 'package:chart/pages/assistant-item/index.dart';
import 'package:chart/pages/assistant/index.dart'; import 'package:chart/pages/assistant/index.dart';
import 'package:chart/pages/chat/view.dart'; import 'package:chart/pages/chat/view.dart';
import 'package:chart/pages/creation-detail/index.dart'; import 'package:chart/pages/creation-detail/index.dart';
import 'package:chart/pages/creation/history/detail/index.dart';
import 'package:chart/pages/creation/history/index.dart'; import 'package:chart/pages/creation/history/index.dart';
import 'package:chart/pages/creation/index.dart'; import 'package:chart/pages/creation/index.dart';
import 'package:chart/pages/eula/bindings.dart'; import 'package:chart/pages/eula/bindings.dart';
...@@ -182,6 +183,11 @@ class AppPages { ...@@ -182,6 +183,11 @@ class AppPages {
page: () => CreateHistoryPage(), page: () => CreateHistoryPage(),
binding: CreateHistoryBinding(), binding: CreateHistoryBinding(),
), ),
GetPage(
name: AppRoutes.CREATION_HISTORY_DETAIL_PAGE,
page: () => const CreateHistoryDetailPage(),
binding: CreateHistoryDetailBinding(),
),
GetPage( GetPage(
name: AppRoutes.ASSISTANT_PAGE, name: AppRoutes.ASSISTANT_PAGE,
page: () => AssistantPage(), page: () => AssistantPage(),
......
...@@ -120,6 +120,7 @@ class CreationDetailController extends GetxController { ...@@ -120,6 +120,7 @@ class CreationDetailController extends GetxController {
model.object = inputControllerMap["input1"]?.text ?? ""; model.object = inputControllerMap["input1"]?.text ?? "";
model.subject = inputControllerMap["input2"]?.text ?? ""; model.subject = inputControllerMap["input2"]?.text ?? "";
model.content = state.genText; model.content = state.genText;
model.title = model.content.length > 5 ? model.content.substring(0, 5) : model.content;
model.date = "${date.year}-${date.month < 10 ? "0${date.month}" : date.month}-${date.day < 10 ? "0${date.day}" : date.day} ${date.hour < 10 ? "0${date.hour}" : date.hour}:${date.minute < 10 ? "0${date.minute}" : date.minute}:${date.second < 10 ? "0${date.second}" : date.second}"; model.date = "${date.year}-${date.month < 10 ? "0${date.month}" : date.month}-${date.day < 10 ? "0${date.day}" : date.day} ${date.hour < 10 ? "0${date.hour}" : date.hour}:${date.minute < 10 ? "0${date.minute}" : date.minute}:${date.second < 10 ? "0${date.second}" : date.second}";
DBTool.insert(model); DBTool.insert(model);
return; return;
......
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
import '../../../common/db/db_tool.dart'; import '../../../common/db/db_tool.dart';
class DetailModel implements DBModel { class DetailModel implements DBModel {
static const TableName = "DetailModel";
var type = ""; var type = "";
var title = "";
var object = ""; var object = "";
var subject = ""; var subject = "";
var content = ""; var content = "";
var date = ""; var date = "";
@override @override
String get tableName => TableName; String get tableName => "DetailModel";
@override @override
String get createTableSql => "CREATE TABLE $tableName (id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, object TEXT, subject TEXT, content TEXT, date TEXT)"; String get createTableSql => "CREATE TABLE $tableName (id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, object TEXT, subject TEXT, content TEXT, date TEXT, title TEXT)";
@override @override
Map<String, Object> get mapValues => {"type": type, "object": object, "subject": subject, "content": content, "date": date}; Map<String, Object> get mapValues => {"type": type, "object": object, "subject": subject, "content": content, "date": date, "title": title};
static DetailModel fromJson(Map<String, Object?> jsonData) { static DetailModel fromJson(Map<String, Object?> jsonData) {
final model = DetailModel(); final model = DetailModel();
...@@ -25,6 +25,7 @@ class DetailModel implements DBModel { ...@@ -25,6 +25,7 @@ class DetailModel implements DBModel {
model.object = jsonData["object"] as String? ?? ""; model.object = jsonData["object"] as String? ?? "";
model.subject = jsonData["subject"] as String? ?? ""; model.subject = jsonData["subject"] as String? ?? "";
model.date = jsonData["date"] as String? ?? ""; model.date = jsonData["date"] as String? ?? "";
model.title = jsonData["title"] as String? ?? "";
return model; return model;
} }
......
...@@ -7,7 +7,6 @@ import '../../../common/db/db_tool.dart'; ...@@ -7,7 +7,6 @@ import '../../../common/db/db_tool.dart';
class CreateHistoryController extends GetxController { class CreateHistoryController extends GetxController {
CreateHistoryController(); CreateHistoryController();
static CreateHistoryController get to => Get.put(CreateHistoryController()); static CreateHistoryController get to => Get.put(CreateHistoryController());
final state = CreateHistoryState(); final state = CreateHistoryState();
getHistoryMoels() { getHistoryMoels() {
...@@ -17,4 +16,16 @@ class CreateHistoryController extends GetxController { ...@@ -17,4 +16,16 @@ class CreateHistoryController extends GetxController {
}); });
} }
searchHistory(String value) {
final where = value.isNotEmpty ? "title LIKE '%$value%'" : null;
DBTool.query(DetailModel(), where: where).then((value) {
final list = value.map((e) => DetailModel.fromJson(e)).toList();
state.models.value = list;
});
}
deleteHistory(DetailModel model) {
DBTool.delete(model, where: "date = '${model.date}'");//.then((value) => getHistoryMoels());
}
} }
\ No newline at end of file
import './controller.dart';
import 'package:get/get.dart';
class CreateHistoryDetailBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<CreateHistoryDetailController>(() => CreateHistoryDetailController());
}
}
\ No newline at end of file
import 'package:chart/pages/creation/history/detail/state.dart';
import 'package:get/get.dart';
class CreateHistoryDetailController extends GetxController {
CreateHistoryDetailController();
static CreateHistoryDetailController get to => Get.put(CreateHistoryDetailController());
final state = CreateHistoryDetailState();
}
\ No newline at end of file
library creation_history_detail;
export './controller.dart';
export './view.dart';
export './bindings.dart';
\ No newline at end of file
import 'package:get/get.dart';
import '../../../creation-detail/models/detail_model.dart';
class CreateHistoryDetailState {
var model = DetailModel().obs;
}
\ No newline at end of file
import './controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class CreateHistoryDetailPage extends GetView<CreateHistoryDetailController> {
const CreateHistoryDetailPage({Key? key}) : super(key: key);
Widget _mainView() {
return Obx(() => Container(
padding: const EdgeInsets.all(15),
width: double.infinity,
child: Column(crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("类型:${controller.state.model.value.type} \n时间:${controller.state.model.value.date}", textAlign: TextAlign.start,),
const SizedBox(height: 15,),
Container(
padding: const EdgeInsets.all(20),
width: Get.width,
constraints: const BoxConstraints(minHeight: 300),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4),
gradient: const LinearGradient(colors: [
Color.fromARGB(
255, 40, 40, 57),
Color.fromARGB(
255, 40, 40, 57),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Text(controller.state.model.value.content))
])
));
}
@override
Widget build(BuildContext context) {
return GetBuilder<CreateHistoryDetailController>(id: "history_detail", init: CreateHistoryDetailController(),
builder: (_) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/background.png").image,
fit: BoxFit.cover),
),
child: Scaffold(
backgroundColor: Color.fromARGB(0, 29, 33, 60),
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 29, 33, 60),
title: Obx(() => Text(
controller.state.model.value.title,
)),
elevation: 0),
body: SafeArea(child: _mainView()),
)
);
});
}
}
\ No newline at end of file
import './detail/controller.dart';
import 'package:chart/common/routers/routes.dart';
import 'package:chart/pages/creation/history/controller.dart'; import 'package:chart/pages/creation/history/controller.dart';
import 'package:chart/pages/creation/history/detail/view.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class SearchSliverAppBar extends SliverPersistentHeaderDelegate {
final double expandedHeight;
final Widget searchBar;
SearchSliverAppBar({required this.expandedHeight, required this.searchBar});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
padding: const EdgeInsets.all(15),
color: const Color.fromARGB(255, 29, 33, 60),
child: Column(
children: [
searchBar,
],
),
);
}
@override
double get maxExtent => expandedHeight;
@override
double get minExtent => expandedHeight;
@override
bool shouldRebuild(covariant SearchSliverAppBar oldDelegate) {
return expandedHeight != oldDelegate.expandedHeight ||
searchBar != oldDelegate.searchBar;
}
}
class CreateHistoryPage extends GetView<CreateHistoryController> { class CreateHistoryPage extends GetView<CreateHistoryController> {
const CreateHistoryPage({Key? key}) : super(key: key); CreateHistoryPage({Key? key}) : super(key: key);
Widget _makeCell(int index) {
final model = controller.state.models[index];
return GestureDetector(
onTap: () {
CreateHistoryDetailController.to.state.model.value = model;
Get.toNamed(AppRoutes.CREATION_HISTORY_DETAIL_PAGE);
},
child: Container(
padding: const EdgeInsets.all(15),
width: double.infinity,
child: Column(crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("类型:${model.type}\n标题:${model.title}\n时间:${model.date}"),
const SizedBox(height: 15,),
Container(
padding: const EdgeInsets.all(20),
width: Get.width,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4),
gradient: const LinearGradient(colors: [
Color.fromARGB(
255, 40, 40, 57),
Color.fromARGB(
255, 40, 40, 57),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Text(model.content, overflow: TextOverflow.ellipsis, maxLines: 3,))
]),
)
);
}
Widget _mainView() { Widget _makeTableView() {
return Obx(() => ListView( final border = OutlineInputBorder(
children: controller.state.models.map((e) { borderRadius: BorderRadius.circular(22.0),
return Container( borderSide: const BorderSide(color:Color(0xFFb05ddd))
padding: const EdgeInsets.all(15), );
width: double.infinity, return Obx(() => CustomScrollView(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, slivers: [
children: [ SliverPersistentHeader(pinned: true,
Text("类型:${e.type} \n时间:${e.date}", textAlign: TextAlign.start,), delegate: SearchSliverAppBar(
const SizedBox(height: 15,), expandedHeight: 78.0,
Container( searchBar: TextField(
padding: const EdgeInsets.all(20), onChanged: (value) {
width: Get.width, controller.searchHistory(value);
constraints: const BoxConstraints(minHeight: 300), },
decoration: BoxDecoration( style: const TextStyle(
borderRadius: fontWeight: FontWeight.w400,
BorderRadius.circular(4), fontSize: 14,
gradient: const LinearGradient(colors: [ ),
Color.fromARGB( maxLines: 1,
255, 40, 40, 57), decoration: InputDecoration(
Color.fromARGB( hintText: '搜索标题',
255, 40, 40, 57), border: border,
], enabledBorder: border,
begin: Alignment.topCenter, focusedBorder: border,
end: Alignment.bottomCenter, disabledBorder: border,
), contentPadding: const EdgeInsets.symmetric(horizontal: 15),
hintStyle: TextStyle(color: Colors.grey[400]),
),
)
)
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final model = controller.state.models[index];
return Dismissible(
key: Key(model.date),
direction: DismissDirection.endToStart,
onDismissed: (direction) {
controller.state.models.removeAt(index);
controller.deleteHistory(model);
},
background: Container(
color: Colors.red,
alignment: Alignment.centerRight,
child: const Padding(
padding: EdgeInsets.only(right: 16.0),
child: Icon(Icons.delete, color: Colors.white),
), ),
child: Text(e.content)) ),
]), child: _makeCell(index)
); );
}).toList() },
childCount: controller.state.models.length,
),
),
],
)); ));
} }
...@@ -51,14 +150,14 @@ class CreateHistoryPage extends GetView<CreateHistoryController> { ...@@ -51,14 +150,14 @@ class CreateHistoryPage extends GetView<CreateHistoryController> {
fit: BoxFit.cover), fit: BoxFit.cover),
), ),
child: Scaffold( child: Scaffold(
backgroundColor: Color.fromARGB(0, 29, 33, 60), backgroundColor: const Color.fromARGB(0, 29, 33, 60),
appBar: AppBar( appBar: AppBar(
backgroundColor: Color.fromARGB(255, 29, 33, 60), backgroundColor: const Color.fromARGB(255, 29, 33, 60),
title: const Text( title: const Text(
"创作记录", "创作记录",
), ),
elevation: 0), elevation: 0),
body: SafeArea(child: _mainView()), body: SafeArea(child: _makeTableView()),
) )
); );
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment