[flutter]监听系统主题改变

/ 68评论 / 1503阅读 / 0点赞

项目需要跟随系统主题变化,修改一些自定义组件的样式,但百度一直没找到可以监听系统主题变化的方法,而 MaterialApp 是有一个设置ThemeMode.system,使得app可以跟随系统主题变化而切换使用传入的theme和darkTheme,因此我就去看了看里面的源码,找到了监听系统主题变化的函数绑定方法。

解决

import 'dart:ui' as ui;
    ui.PlatformDispatcher.instance.onPlatformBrightnessChanged = () {
      // 设置跟随系统主题变化
      followingSystem();
    };
ui.PlatformDispatcher.instance.onPlatformBrightnessChanged = null;
if(null == ui.PlatformDispatcher.instance.onPlatformBrightnessChanged) {
    // 当前没有在监听
} else {
    // 有在监听
}
    ui.PlatformDispatcher.instance.onPlatformBrightnessChanged = () {
       fun1();
       fun2();
       fun3();
       fun4();
       ......
    };
if(ui.PlatformDispatcher.instance.platformBrightness == Brightness.dark) {
    // 系统已经转变为夜间模式
    // app跟随修改主题为夜间
} else {
    // 系统已经转变为白天模式
    // app跟随修改主题为白天
}
// 进入app时手动调用一次 followingSystem(), 然后调用 setFollowingSystem() 绑定监听函数

  void followingSystem() {
    if (ui.PlatformDispatcher.instance.platformBrightness == Brightness.dark) {
      // app跟随修改主题为夜间
    } else {
      // app跟随修改主题为白天
    }
  }

  // 设置跟随系统主题变化
  void setFollowingSystem() {
    ui.PlatformDispatcher.instance.onPlatformBrightnessChanged = () {
      followingSystem();
    };
  }
  1. Scottvaw说道:

    casibom güncel
    Nihai Dönemsel En Fazla Gözde Bahis Platformu: Casibom

    Bahis oyunlarını sevenlerin artık duymuş olduğu Casibom, nihai dönemde adından sıkça söz ettiren bir bahis ve oyun web sitesi haline geldi. Ülkemizdeki en mükemmel kumarhane platformlardan biri olarak tanınan Casibom’un haftalık olarak olarak değişen erişim adresi, sektörde oldukça taze olmasına rağmen emin ve kar getiren bir platform olarak ön plana çıkıyor.

    Casibom, rakiplerini geride kalarak köklü bahis web sitelerinin önüne geçmeyi başarılı oluyor. Bu pazarda köklü olmak önemlidir olsa da, oyunculardan iletişim kurmak ve onlara ulaşmak da benzer miktar değerli. Bu noktada, Casibom’un her saat servis veren gerçek zamanlı destek ekibi ile rahatlıkla iletişime geçilebilir olması büyük bir fayda sağlıyor.

    Hızlıca büyüyen oyuncuların kitlesi ile dikkat çekici olan Casibom’un arka planında başarılı faktörleri arasında, sadece ve yalnızca casino ve canlı olarak casino oyunları ile sınırlı olmayan geniş bir servis yelpazesi bulunuyor. Spor bahislerinde sunduğu geniş alternatifler ve yüksek oranlar, oyuncuları cezbetmeyi başarıyor.

    Ayrıca, hem spor bahisleri hem de bahis oyunlar oyuncularına yönelik sunulan yüksek yüzdeli avantajlı ödüller da dikkat çekiyor. Bu nedenle, Casibom hızla alanında iyi bir reklam başarısı elde ediyor ve büyük bir oyuncu kitlesi kazanıyor.

    Casibom’un kazandıran bonusları ve popülerliği ile birlikte, platforma üyelik ne şekilde sağlanır sorusuna da değinmek elzemdir. Casibom’a mobil cihazlarınızdan, bilgisayarlarınızdan veya tabletlerinizden web tarayıcı üzerinden kolaylıkla erişilebilir. Ayrıca, sitenin mobil uyumlu olması da önemli bir artı sunuyor, çünkü artık neredeyse herkesin bir akıllı telefonu var ve bu telefonlar üzerinden hızlıca giriş sağlanabiliyor.

    Taşınabilir cep telefonlarınızla bile yolda canlı bahisler alabilir ve maçları canlı olarak izleyebilirsiniz. Ayrıca, Casibom’un mobil uyumlu olması, ülkemizde kumarhane ve casino gibi yerlerin kanuni olarak kapatılmasıyla birlikte bu tür platformlara erişimin önemli bir yolunu oluşturuyor.

    Casibom’un itimat edilir bir casino platformu olması da önemlidir bir artı sağlıyor. Ruhsatlı bir platform olan Casibom, kesintisiz bir şekilde eğlence ve kazanç sağlama imkanı getirir.

    Casibom’a abone olmak da oldukça kolaydır. Herhangi bir belge koşulu olmadan ve bedel ödemeden web sitesine rahatça kullanıcı olabilirsiniz. Ayrıca, web sitesi üzerinde para yatırma ve çekme işlemleri için de çok sayıda farklı yöntem vardır ve herhangi bir kesim ücreti isteseniz de alınmaz.

    Ancak, Casibom’un güncel giriş adresini takip etmek de önemlidir. Çünkü canlı bahis ve oyun platformlar popüler olduğu için yalancı platformlar ve dolandırıcılar da belirmektedir. Bu nedenle, Casibom’un sosyal medya hesaplarını ve güncel giriş adresini düzenli aralıklarla kontrol etmek elzemdir.

    Sonuç, Casibom hem itimat edilir hem de kar getiren bir casino web sitesi olarak dikkat çekiyor. yüksek bonusları, kapsamlı oyun seçenekleri ve kullanıcı dostu mobil uygulaması ile Casibom, casino sevenler için ideal bir platform sağlar.

  2. Scottvaw说道:

    Rolex watches
    Understanding COSC Certification and Its Importance in Watchmaking
    COSC Validation and its Stringent Standards
    COSC, or the Official Swiss Chronometer Testing Agency, is the authorized Swiss testing agency that attests to the accuracy and precision of wristwatches. COSC validation is a sign of excellent craftsmanship and dependability in timekeeping. Not all watch brands seek COSC validation, such as Hublot, which instead adheres to its own demanding standards with movements like the UNICO, attaining comparable accuracy.

    The Art of Exact Chronometry
    The core mechanism of a mechanized timepiece involves the spring, which supplies power as it unwinds. This mechanism, however, can be prone to external factors that may influence its accuracy. COSC-validated mechanisms undergo rigorous testing—over 15 days in various circumstances (five positions, 3 temperatures)—to ensure their durability and dependability. The tests evaluate:

    Mean daily rate accuracy between -4 and +6 seconds.
    Mean variation, peak variation rates, and impacts of temperature changes.
    Why COSC Certification Is Important
    For watch enthusiasts and connoisseurs, a COSC-certified watch isn’t just a piece of tech but a testament to lasting excellence and precision. It symbolizes a watch that:

    Offers excellent dependability and accuracy.
    Offers guarantee of superiority across the complete construction of the watch.
    Is likely to retain its value better, making it a wise choice.
    Famous Timepiece Manufacturers
    Several famous brands prioritize COSC validation for their watches, including Rolex, Omega, Breitling, and Longines, among others. Longines, for instance, offers collections like the Archive and Spirit, which feature COSC-validated movements equipped with cutting-edge materials like silicone equilibrium springs to improve durability and efficiency.

    Historical Background and the Development of Chronometers
    The idea of the timepiece dates back to the requirement for precise chronometry for navigation at sea, emphasized by John Harrison’s work in the 18th century. Since the formal establishment of Controle Officiel Suisse des Chronometres in 1973, the validation has become a standard for assessing the accuracy of luxury watches, sustaining a legacy of excellence in horology.

    Conclusion
    Owning a COSC-certified timepiece is more than an visual selection; it’s a commitment to excellence and accuracy. For those valuing accuracy above all, the COSC certification provides peacefulness of mind, ensuring that each certified timepiece will perform reliably under various conditions. Whether for individual contentment or as an investment, COSC-certified watches distinguish themselves in the world of horology, carrying on a tradition of precise chronometry.

  3. LarryGok说道:

    PBN sites
    We’ll create a structure of privately-owned blog network sites!

    Benefits of our privately-owned blog network:

    We perform everything so GOOGLE does not comprehend THAT this A self-owned blog network!!!

    1- We purchase domain names from various registrars

    2- The leading site is hosted on a VPS server (VPS is rapid hosting)

    3- Other sites are on various hostings

    4- We allocate a individual Google profile to each site with verification in Google Search Console.

    5- We develop websites on WordPress, we don’t employ plugins with assistance from which Trojans penetrate and through which pages on your websites are generated.

    6- We refrain from repeat templates and employ only exclusive text and pictures

    We don’t work with website design; the client, if wished, can then edit the websites to suit his wishes

  4. dobry sklep说道:

    Wow, superb weblog structure! How long have you ever been running a blog for?
    you make running a blog look easy. The full glance of your web site is excellent, as
    smartly as the content! You can see similar here e-commerce

  5. ラブドール アニメ キャラ 138cmアイアンテックリーズナブルラブドールDoll4Ever165cm –5ft5巨大な胸新しいWM人形168cm–5ft6ビスチェで覆われた大きなヒップの小さなおっぱい

  6. hitman.Agency说道:

    Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get
    my blog to rank for some targeted keywords but I’m not seeing
    very good results. If you know of any please share. Thanks!
    You can read similar blog here: GSA List

  7. Hi! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying
    to get my site to rank for some targeted keywords but I’m not
    seeing very good success. If you know of any please share.
    Thank you! I saw similar blog here: Auto Approve List

  8. najlepszy sklep说道:

    Hello there! Do you know if they make any plugins to assist with Search
    Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not
    seeing very good success. If you know of any please share.

    Many thanks! You can read similar article here: Sklep online

  9. najlepszy sklep说道:

    Wow, fantastic blog structure! How long have you ever been running a blog for?

    you made running a blog look easy. The total glance of your website is
    wonderful, as neatly as the content material! You can see similar here ecommerce

  10. hd porn videos download ggjgodherogg.8fMb7gOEkoG

  11. Ignatius Rolfson说道:

    Hi Neat post Theres an issue together with your web site in internet explorer may test this IE still is the marketplace chief and a good component of people will pass over your fantastic writing due to this problem

  12. temp mail说道:

    Hello, I thought you had looked at my blog, so I came back to say hello. Since I’m trying to improve my website, I suppose I can use some of your advice.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注