cache
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
|
||||
import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/controller.dart';
|
||||
import 'package:fl_clash/core/controller.dart';
|
||||
import 'package:fl_clash/enum/enum.dart';
|
||||
import 'package:fl_clash/features/overwrite/rule.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/pages/editor.dart';
|
||||
import 'package:fl_clash/providers/database.dart';
|
||||
import 'package:fl_clash/providers/providers.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:fl_clash/views/config/scripts.dart';
|
||||
import 'package:fl_clash/views/profiles/preview.dart';
|
||||
import 'package:fl_clash/widgets/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -37,13 +36,7 @@ class _OverwriteViewState extends ConsumerState<OverwriteView> {
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
final configMap = await appController.getProfileWithId(profile.id);
|
||||
final content = await encodeYamlTask(configMap);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
final previewPage = EditorPage(title: profile.realLabel, content: content);
|
||||
BaseNavigator.push<String>(context, previewPage);
|
||||
BaseNavigator.push<String>(context, PreviewProfileView(profile: profile));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -181,10 +174,10 @@ class _StandardContent extends ConsumerStatefulWidget {
|
||||
const _StandardContent(this.profileId);
|
||||
|
||||
@override
|
||||
ConsumerState createState() => __StandardContentState();
|
||||
ConsumerState createState() => _StandardContentState();
|
||||
}
|
||||
|
||||
class __StandardContentState extends ConsumerState<_StandardContent> {
|
||||
class _StandardContentState extends ConsumerState<_StandardContent> {
|
||||
final _key = utils.id;
|
||||
|
||||
Future<void> _handleAddOrUpdate([Rule? rule]) async {
|
||||
|
||||
61
lib/views/profiles/preview.dart
Normal file
61
lib/views/profiles/preview.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:fl_clash/common/task.dart';
|
||||
import 'package:fl_clash/controller.dart';
|
||||
import 'package:fl_clash/models/profile.dart';
|
||||
import 'package:fl_clash/pages/editor.dart';
|
||||
import 'package:fl_clash/widgets/loading.dart';
|
||||
import 'package:fl_clash/widgets/scaffold.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PreviewProfileView extends StatefulWidget {
|
||||
final Profile profile;
|
||||
|
||||
const PreviewProfileView({super.key, required this.profile});
|
||||
|
||||
@override
|
||||
State<PreviewProfileView> createState() => _PreviewProfileViewState();
|
||||
}
|
||||
|
||||
class _PreviewProfileViewState extends State<PreviewProfileView> {
|
||||
final contentNotifier = ValueNotifier<String?>(null);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
final configMap = await appController.getProfileWithId(widget.profile.id);
|
||||
final content = await encodeYamlTask(configMap);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
contentNotifier.value = content;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
contentNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: contentNotifier,
|
||||
builder: (_, content, _) {
|
||||
final title = widget.profile.realLabel;
|
||||
if (content == null) {
|
||||
return CommonScaffold(
|
||||
title: title,
|
||||
body: Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 200,
|
||||
child: CommonCircleLoading(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return EditorPage(title: title, content: content);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/controller.dart';
|
||||
import 'package:fl_clash/enum/enum.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/pages/editor.dart';
|
||||
import 'package:fl_clash/providers/providers.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:fl_clash/views/profiles/overwrite/overwrite.dart';
|
||||
@@ -13,6 +12,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'add.dart';
|
||||
import 'edit.dart';
|
||||
import 'preview.dart';
|
||||
|
||||
class ProfilesView extends StatefulWidget {
|
||||
const ProfilesView({super.key});
|
||||
@@ -198,14 +198,7 @@ class ProfileItem extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future<void> _handlePreview(BuildContext context) async {
|
||||
final configMap = await appController.getProfileWithId(profile.id);
|
||||
final content = await encodeYamlTask(configMap);
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final previewPage = EditorPage(title: profile.realLabel, content: content);
|
||||
BaseNavigator.push<String>(context, previewPage);
|
||||
BaseNavigator.push<String>(context, PreviewProfileView(profile: profile));
|
||||
}
|
||||
|
||||
Future updateProfile() async {
|
||||
|
||||
Reference in New Issue
Block a user