Skip to content

Commit

Permalink
Monet color support
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Aug 28, 2024
1 parent 7ab0c88 commit c768072
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 31 deletions.
1 change: 1 addition & 0 deletions lib/controllers/progressbar_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ProgressbarController extends GetxController {

_updateWidget(bool loading) {
if (loading)
// 不要修改,会炸
widget.value = Container(
child: LinearProgressIndicator(
value: null,
Expand Down
80 changes: 59 additions & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miofeed/controllers/progressbar_controller.dart';
import 'package:miofeed/ui/home.dart';
import 'package:miofeed/ui/paragraph.dart';
import 'package:miofeed/ui/settings.dart';
import 'package:miofeed/ui/settings/render.dart';
import 'package:miofeed/ui/settings/rss_sub.dart';
import 'package:miofeed/ui/settings/theme.dart';
import 'package:miofeed/utils/rss/rss_cache.dart';
Expand All @@ -21,31 +22,68 @@ void main() async {
class MyApp extends StatelessWidget {
const MyApp({super.key});

// 默认主题色种子
static const _defaultColorSeed = Colors.blueAccent;

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Get.put(ProgressbarController());
return GetMaterialApp(
title: 'MioFeed',
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blueAccent,
fontFamily: 'Microsoft YaHei',
),
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: Colors.blueAccent,
fontFamily: 'Microsoft YaHei',
),
themeMode: ThemeMode.system,
routes: {
'/home': (context) => HomeUI(title: title),
'/settings': (context) => SettingsUI(title: title),
'/settings/rss_sub': (context) => const RssSubSettingUI(title: title),
'/settings/theme': (context) => ThemeSettingUI(title: title),
// Monet 取色
return DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
ColorScheme lightColorScheme;
ColorScheme darkColorScheme;

if (lightDynamic != null && darkDynamic != null) {
// On Android S+ devices, use the provided dynamic color scheme.
// (Recommended) Harmonize the dynamic color scheme' built-in semantic colors.
lightColorScheme = lightDynamic.harmonized();
// (Optional) Customize the scheme as desired. For example, one might
// want to use a brand color to override the dynamic [ColorScheme.secondary].
// lightColorScheme = lightColorScheme.copyWith(secondary: _defaultColorSeed);
// (Optional) If applicable, harmonize custom colors.
// lightCustomColors = lightCustomColors.harmonized(lightColorScheme);

// Repeat for the dark color scheme.
darkColorScheme = darkDynamic.harmonized();
// darkColorScheme = darkColorScheme.copyWith(secondary: _defaultColorSeed);
// darkCustomColors = darkCustomColors.harmonized(darkColorScheme);
} else {
// Fallback
lightColorScheme = ColorScheme.fromSeed(
seedColor: _defaultColorSeed,
);
darkColorScheme = ColorScheme.fromSeed(
seedColor: _defaultColorSeed,
brightness: Brightness.dark,
);
}
return GetMaterialApp(
title: 'MioFeed',
theme: ThemeData(
useMaterial3: true,
colorScheme: lightColorScheme,
fontFamily: 'Microsoft YaHei',
),
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorScheme: darkColorScheme,
fontFamily: 'Microsoft YaHei',
),
themeMode: ThemeMode.system,
routes: {
'/home': (context) => HomeUI(title: title),
'/settings': (context) => SettingsUI(title: title),
'/settings/rss_sub': (context) =>
const RssSubSettingUI(title: title),
'/settings/theme': (context) => ThemeSettingUI(title: title),
'/settings/render': (context) => RenderSettingUI(title: title),
},
home: HomeUI(title: title),
);
},
home: HomeUI(title: title),
);
}
}
2 changes: 0 additions & 2 deletions lib/models/universal_item.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:miofeed/models/universal_feed.dart';

import 'generator.dart';

class UniversalItem {
Expand Down
9 changes: 9 additions & 0 deletions lib/ui/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class SettingsUI extends StatelessWidget {
Get.toNamed('/settings/theme');
},
),
InkWell(
child: const ListTile(
leading: Icon(Icons.view_in_ar),
title: Text("渲染设置"),
),
onTap: () async {
Get.toNamed('/settings/render');
},
),
],
),
bottomNavigationBar: NavigationBarX().build(),
Expand Down
33 changes: 33 additions & 0 deletions lib/ui/settings/render.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../controllers/progressbar_controller.dart';
import '../models/navigation_bar.dart';

class RenderSettingUI extends StatelessWidget {
RenderSettingUI({super.key, required this.title});

final String title;

final ProgressbarController progressbar = Get.find();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
bottom: PreferredSize(
preferredSize: Size(MediaQuery.of(context).size.width, 3),
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 3,
child: Obx(() => progressbar.widget.value),
),
),
),
body: const Center(
child: Text('Coming soon'),
),
bottomNavigationBar: NavigationBarX().build(),
);
}
}
15 changes: 10 additions & 5 deletions lib/ui/settings/rss_sub/new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,16 @@ class _RssSubNewState extends State<RssSubNewUI> {
try {
res = await NetworkGetRss().get(rssSubLinkTextController.text);
} catch (e, s) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("无法请求订阅,请检查订阅链接是否正确或重试!"),
),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"无法请求订阅,请检查订阅链接是否正确或重试!"),
),
);
}
print(e);
print(s);
progressbar.finish();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/settings/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ThemeSettingUI extends StatelessWidget {
),
),
),
body: Center(
child: Text('test'),
body: const Center(
child: Text('Coming soon'),
),
bottomNavigationBar: NavigationBarX().build(),
);
Expand Down
1 change: 1 addition & 0 deletions lib/utils/paragraph_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:miofeed/utils/color.dart' as color_utils;

class ParagraphUtils {
/// 通过订阅名生成文字图标
static Widget buildColorIcon(String subName) {
return Container(
color: color_utils.Color.stringToColor(subName),
Expand Down
1 change: 0 additions & 1 deletion lib/utils/rss/rss_cache.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:convert';
import 'dart:io';

import 'package:dart_rss/dart_rss.dart';
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <dynamic_color/dynamic_color_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
url_launcher_linux
)

Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FlutterMacOS
import Foundation

import audio_session
import dynamic_color
import just_audio
import package_info_plus
import path_provider_foundation
Expand All @@ -19,6 +20,7 @@ import webview_flutter_wkwebview

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
dynamic_color:
dependency: "direct main"
description:
name: dynamic_color
sha256: eae98052fa6e2826bdac3dd2e921c6ce2903be15c6b7f8b6d8a5d49b5086298d
url: "https://pub.dev"
source: hosted
version: "1.7.0"
fake_async:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies:
url_launcher: ^6.3.0
share_plus: ^10.0.2
intl: ^0.19.0
dynamic_color: ^1.7.0

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include "generated_plugin_registrant.h"

#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
share_plus
url_launcher_windows
)
Expand Down

0 comments on commit c768072

Please sign in to comment.