Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

期望提供的默认样式能兼容Dark暗黑模式 #205

Closed
davidche1116 opened this issue Jul 19, 2024 · 5 comments
Closed

期望提供的默认样式能兼容Dark暗黑模式 #205

davidche1116 opened this issue Jul 19, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@davidche1116
Copy link

davidche1116 commented Jul 19, 2024

版本信息

  • Flutter版本:3.22.3
  • flutter_smart_dialog版本:4.9.7+8

描述需求

Loading 和 Toast 提供的默认样式已经很好看了。想在不自定义样式的情况下,能自动兼容Dark暗黑模式。当前在暗黑模式下,Loading和Toast黑色背景不太明显。或者把背景颜色、字体颜色参数能提供出来。
判断当前是否为暗黑模式:Theme.of(context).brightness == Brightness.dark

问题demo

import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      darkTheme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple, brightness: Brightness.dark),
        brightness: Brightness.dark,
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    SmartDialog.showToast('你按了一下按钮');
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
@xdd666t xdd666t self-assigned this Jul 19, 2024
@xdd666t
Copy link
Member

xdd666t commented Jul 19, 2024

  • 有些人的app适配了暗黑, 有些人没适配, 对于没适配暗黑模式app来说, 我把默认样式适配的暗黑就会有问题; 同时是否跟随系统的暗黑样式, 在app里面可能还有相关的配置去控制

  • 目前还是希望有定制化需求的, 去自定义样式, 默认样式仅仅提供样式占位的功能, SmartDialog可以非常方便的全局替换默认样式: SmartDialog在各类路由框架中如何初始化 #131

image

  • 同时, 你可以把默认样式的文件拷贝出来调整下即可使用, 每个文件都可以单独运行

image

@davidche1116
Copy link
Author

不是想把默认的样式改为暗黑模式,而是希望默认样式能自动判断当前APP是否为暗黑模式,若是,则响应的样式智能改变。就像demo里写的MaterialApp,设置了theme和darkTheme两个参数后,手机系统里设置相应模式后,APP能自动改变,无需做其他处理。

@davidche1116
Copy link
Author

不是想把默认的样式改为暗黑模式,而是希望默认样式能自动判断当前APP是否为暗黑模式,若是,则响应的样式智能改变。就像demo里写的MaterialApp,设置了theme和darkTheme两个参数后,手机系统里设置相应模式后,APP能自动改变,无需做其他处理。

@xdd666t

@xdd666t
Copy link
Member

xdd666t commented Jul 20, 2024

简单的调整了下默认样式,只是为了在暗黑模式能保证toast和loading至少可见,怎么说呢? 样式上可能不太符合你的预期

说明下,默认相关字体和背景样式是不会暴露出去的,因为这是完全完全没有必要的,对外暴露的api越多,会导致库的使用越来越让人费解,我一直都是比较谨慎的控制api的增加

默认样式仅仅只是为了占位,使得开发者首次使用时,能有个样式反馈,默认样式的代码也是非常简单,多数仅仅十几行,默认的那些widget是完全不值得提供相关的api,让开发者去定制的

所有你有更多的定制需求,还是希望你使用上面所说的,去替换下全局的默认样式

dependencies:
  flutter_smart_dialog: ^4.9.7+9

@davidche1116
Copy link
Author

@xdd666t 是我想要的默认样式。完美。感谢!

简单的调整了下默认样式,只是为了在暗黑模式能保证toast和loading至少可见,怎么说呢? 样式上可能不太符合你的预期

说明下,默认相关字体和背景样式是不会暴露出去的,因为这是完全完全没有必要的,对外暴露的api越多,会导致库的使用越来越让人费解,我一直都是比较谨慎的控制api的增加

默认样式仅仅只是为了占位,使得开发者首次使用时,能有个样式反馈,默认样式的代码也是非常简单,多数仅仅十几行,默认的那些widget是完全不值得提供相关的api,让开发者去定制的

所有你有更多的定制需求,还是希望你使用上面所说的,去替换下全局的默认样式

dependencies:
  flutter_smart_dialog: ^4.9.7+9

@xdd666t xdd666t added the enhancement New feature or request label Jul 20, 2024
@xdd666t xdd666t closed this as completed Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants