2024-08-15 16:18:00 +08:00
|
|
|
import 'package:fl_clash/common/app_localizations.dart';
|
2024-11-09 20:17:57 +08:00
|
|
|
import 'package:fl_clash/common/system.dart';
|
2024-08-15 16:18:00 +08:00
|
|
|
import 'package:fl_clash/models/models.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
import 'package:fl_clash/widgets/widgets.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
import '../config/network.dart';
|
2024-08-15 16:18:00 +08:00
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
class TUNButton extends StatelessWidget {
|
|
|
|
|
const TUNButton({super.key});
|
2024-08-15 16:18:00 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-09 20:17:57 +08:00
|
|
|
return ButtonContainer(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (_) {
|
|
|
|
|
return generateListView(generateSection(
|
|
|
|
|
items: [
|
|
|
|
|
if (system.isDesktop) const TUNItem(),
|
|
|
|
|
const TunStackItem(),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
title: appLocalizations.tun,
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-08-15 16:18:00 +08:00
|
|
|
info: Info(
|
|
|
|
|
label: appLocalizations.tun,
|
|
|
|
|
iconData: Icons.stacked_line_chart,
|
|
|
|
|
),
|
|
|
|
|
child: Selector<ClashConfig, bool>(
|
|
|
|
|
selector: (_, clashConfig) => clashConfig.tun.enable,
|
|
|
|
|
builder: (_, enable, __) {
|
2024-09-08 21:21:21 +08:00
|
|
|
return LocaleBuilder(
|
|
|
|
|
builder: (_) => Switch(
|
|
|
|
|
value: enable,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
final clashConfig = globalState.appController.clashConfig;
|
|
|
|
|
clashConfig.tun = clashConfig.tun.copyWith(
|
|
|
|
|
enable: value,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-08-15 16:18:00 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
class SystemProxyButton extends StatelessWidget {
|
|
|
|
|
const SystemProxyButton({super.key});
|
2024-08-15 16:18:00 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-09 20:17:57 +08:00
|
|
|
return ButtonContainer(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (_) {
|
|
|
|
|
return generateListView(
|
|
|
|
|
generateSection(
|
|
|
|
|
items: [
|
|
|
|
|
SystemProxyItem(),
|
|
|
|
|
BypassDomainItem(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
title: appLocalizations.systemProxy,
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-08-15 16:18:00 +08:00
|
|
|
info: Info(
|
|
|
|
|
label: appLocalizations.systemProxy,
|
|
|
|
|
iconData: Icons.shuffle,
|
|
|
|
|
),
|
|
|
|
|
child: Selector<Config, bool>(
|
2024-11-09 20:17:57 +08:00
|
|
|
selector: (_, config) => config.networkProps.systemProxy,
|
2024-08-15 16:18:00 +08:00
|
|
|
builder: (_, systemProxy, __) {
|
2024-09-08 21:21:21 +08:00
|
|
|
return LocaleBuilder(
|
|
|
|
|
builder: (_) => Switch(
|
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
value: systemProxy,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
final config = globalState.appController.config;
|
2024-11-09 20:17:57 +08:00
|
|
|
config.networkProps =
|
|
|
|
|
config.networkProps.copyWith(systemProxy: value);
|
2024-09-08 21:21:21 +08:00
|
|
|
},
|
|
|
|
|
),
|
2024-08-15 16:18:00 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
class ButtonContainer extends StatelessWidget {
|
2024-08-15 16:18:00 +08:00
|
|
|
final Info info;
|
|
|
|
|
final Widget child;
|
2024-11-09 20:17:57 +08:00
|
|
|
final VoidCallback onPressed;
|
2024-08-15 16:18:00 +08:00
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
const ButtonContainer({
|
2024-08-15 16:18:00 +08:00
|
|
|
super.key,
|
|
|
|
|
required this.info,
|
|
|
|
|
required this.child,
|
2024-11-09 20:17:57 +08:00
|
|
|
required this.onPressed,
|
2024-08-15 16:18:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return CommonCard(
|
2024-11-09 20:17:57 +08:00
|
|
|
onPressed: onPressed,
|
2024-08-15 16:18:00 +08:00
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
InfoHeader(
|
|
|
|
|
info: info,
|
|
|
|
|
actions: [
|
|
|
|
|
child,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|