Skip to content

Commit

Permalink
以一种非常丑陋的方式实现了功能
Browse files Browse the repository at this point in the history
  • Loading branch information
iris1598 committed Aug 31, 2024
1 parent 0005e44 commit e572c2d
Show file tree
Hide file tree
Showing 30 changed files with 2,199 additions and 252 deletions.
33 changes: 4 additions & 29 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
//google()
//mavenCentral()
maven {
allowInsecureProtocol = true
url 'https://maven.aliyun.com/repository/google'
}
maven {
allowInsecureProtocol = true
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public'
}

google()
mavenCentral()
}

dependencies {
Expand All @@ -26,20 +13,8 @@ buildscript {

allprojects {
repositories {
//google()
//mavenCentral()
maven {
allowInsecureProtocol = true
url 'https://maven.aliyun.com/repository/google'
}
maven {
allowInsecureProtocol = true
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public'
}
google()
mavenCentral()
}
}

Expand Down
39 changes: 39 additions & 0 deletions lib/bean/appbar/drag_to_move_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:miru_app/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

/// A widget for drag to move window.
///
/// When you have hidden the title bar, you can add this widget to move the window position.
///
/// {@tool snippet}
///
/// The sample creates a red box, drag the box to move the window.
///
/// ```dart
/// DragToMoveArea(
/// child: Container(
/// width: 300,
/// height: 32,
/// color: Colors.red,
/// ),
/// )
/// ```
/// {@end-tool}
class DragToMoveArea extends StatelessWidget {
const DragToMoveArea({
Key? key,
required this.child,
}) : super(key: key);

final Widget child;

@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (_) => (Utils.isDesktop()) ? windowManager.startDragging() : null,
child: child,
);
}
}
82 changes: 82 additions & 0 deletions lib/bean/appbar/sys_app_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'dart:io';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:miru_app/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

class SysAppBar extends StatelessWidget implements PreferredSizeWidget {

final double? toolbarHeight;

final Widget? title;

final Color? backgroundColor;

final double? elevation;

final ShapeBorder? shape;

final List<Widget>? actions;

final Widget? leading;

final PreferredSizeWidget? bottom;

const SysAppBar({super.key, this.toolbarHeight, this.title, this.backgroundColor, this.elevation, this.shape, this.actions, this.leading, this.bottom});

void _handleCloseEvent() {
SmartDialog.show(
useAnimation: false,
builder: (context) {
return AlertDialog(
title: const Text('退出确认'),
content: const Text('您想要退出 Kazumi 吗?'),
actions: [
TextButton(
onPressed: () => exit(0),
child: const Text('退出 Kazumi')),
TextButton(
onPressed: () {
SmartDialog.dismiss();
windowManager.hide();
},
child: const Text('最小化至托盘')),
const TextButton(
onPressed: SmartDialog.dismiss,
child: Text('取消')),
],
);
}
);
}

@override
Widget build(BuildContext context) {
List<Widget> acs = [];
if (actions != null) {
acs.addAll(actions!);
}
if (Utils.isDesktop()) {
// acs.add(IconButton(onPressed: () => windowManager.minimize(), icon: const Icon(Icons.minimize)));
acs.add(CloseButton(onPressed: () => _handleCloseEvent()));
}
return GestureDetector(
// behavior: HitTestBehavior.translucent,
onPanStart: (_) => (Utils.isDesktop()) ? windowManager.startDragging() : null,
child: AppBar(
toolbarHeight: preferredSize.height,
scrolledUnderElevation: 0.0,
title: title,
actions: acs,
leading: leading,
backgroundColor: backgroundColor,
elevation: elevation,
shape: shape,
bottom: bottom,
),
);
}

@override
Size get preferredSize => Size.fromHeight(toolbarHeight ?? kToolbarHeight);
}
22 changes: 22 additions & 0 deletions lib/bean/settings/color_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';

final List<Map<String, dynamic>> colorThemeTypes = [
{'color': Colors.green, 'label': '默认'},
{'color': Colors.lightGreen, 'label': '浅绿色'},
{'color': Colors.teal, 'label': '青色'},
{'color': Colors.cyan, 'label': '蓝绿色'},
{'color': Colors.lightBlue, 'label': '浅蓝色'},
{'color': Colors.blue, 'label': '蓝色'},
{'color': Colors.indigo, 'label': '靛蓝色'},
{'color': Colors.purple, 'label': '紫色'},
{'color': Colors.deepPurple, 'label': '深紫色'},
{'color': Colors.pink, 'label': '粉红色'},
{'color': Colors.red, 'label': '红色'},
{'color': Colors.orange, 'label': '橙色'},
{'color': Colors.amber, 'label': '琥珀色'},
{'color': Colors.yellow, 'label': '黄色'},
{'color': Colors.lime, 'label': '酸橙色'},
{'color': Colors.blueGrey, 'label': '蓝灰色'},
{'color': Colors.brown, 'label': '棕色'},
{'color': Colors.grey, 'label': '灰色'},
];
144 changes: 144 additions & 0 deletions lib/bean/settings/settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:hive/hive.dart';
import 'package:miru_app/utils/storage.dart';

class SetSwitchItem extends StatefulWidget {
final String? title;
final String? subTitle;
final String? setKey;
final bool? defaultVal;
final Function? callFn;
final bool? needReboot;

const SetSwitchItem({
this.title,
this.subTitle,
this.setKey,
this.defaultVal,
this.callFn,
this.needReboot,
Key? key,
}) : super(key: key);

@override
State<SetSwitchItem> createState() => _SetSwitchItemState();
}

class _SetSwitchItemState extends State<SetSwitchItem> {
// ignore: non_constant_identifier_names
Box Setting = GStorage.setting;
late bool val;

@override
void initState() {
super.initState();
val = Setting.get(widget.setKey, defaultValue: widget.defaultVal ?? false);
}

void switchChange(value) async {
val = value ?? !val;
await Setting.put(widget.setKey, val);
if (widget.callFn != null) {
widget.callFn!.call(val);
}
if (widget.needReboot != null && widget.needReboot!) {
SmartDialog.showToast('重启生效');
}
setState(() {});
}

@override
Widget build(BuildContext context) {
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
TextStyle subTitleStyle = Theme.of(context)
.textTheme
.labelMedium!
.copyWith(color: Theme.of(context).colorScheme.outline);
return ListTile(
enableFeedback: true,
onTap: () => switchChange(null),
title: Text(widget.title!, style: titleStyle),
subtitle: widget.subTitle != null
? Text(widget.subTitle!, style: subTitleStyle)
: null,
trailing: Transform.scale(
alignment: Alignment.centerRight, // 缩放Switch的大小后保持右侧对齐, 避免右侧空隙过大
scale: 0.8,
child: Switch(
value: val,
onChanged: (val) => switchChange(val),
),
),
);
}
}

class SelectDialog<T> extends StatefulWidget {
final T value;
final String title;
final List<dynamic> values;
const SelectDialog(
{super.key,
required this.value,
required this.values,
required this.title});

@override
_SelectDialogState<T> createState() => _SelectDialogState<T>();
}

class _SelectDialogState<T> extends State<SelectDialog<T>> {
late T _tempValue;

@override
void initState() {
super.initState();
_tempValue = widget.value;
}

@override
Widget build(BuildContext context) {
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;

return AlertDialog(
title: Text(widget.title),
contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (var i in widget.values) ...[
RadioListTile(
value: i['value'],
title: Text(i['title'], style: titleStyle),
groupValue: _tempValue,
onChanged: (value) {
setState(() {
_tempValue = value as T;
});
},
),
]
],
),
);
}),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () => Navigator.pop(context, _tempValue),
child: const Text('确定'),
)
],
);
}
}

Loading

0 comments on commit e572c2d

Please sign in to comment.