Giter Site home page Giter Site logo

flutter_rxdart's Introduction

flutter_state

flutter 状态管理

Getting Started

For help getting started with Flutter, view our online documentation.

flutter_rxdart's People

Contributors

lizhuoyuan avatar

Stargazers

LLemonGreen avatar 像树一样成长! avatar lv avatar

Watchers

James Cloos avatar  avatar

flutter_rxdart's Issues

您好,如何持久化主题状态呢?

退出app后再打开会恢复到日间主题,我尝试使用SharedPreferences来储存一个bool值来记录主题,想要在app初始化的main方法里进行如下处理:

var themeBloc;
void main() async {

  getLoginInfo();
  // await checkChina();

  runApp(BlocProvider(child: App()));

  initTheme();
  SystemUiOverlayStyle systemUiOverlayStyle =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

void initTheme() async {
  SharedPreferences sp = await SharedPreferences.getInstance();
  sp.getBool("isNight");
  print(sp.getBool("isNight"));

  themeBloc.changeTheme(sp.getBool("isNight"));
}

出现如下报错:

出现异常。
NoSuchMethodError (NoSuchMethodError: The method 'changeTheme' was called on null.
Receiver: null
Tried calling: changeTheme(true))

sp.getBool("isNight")是有值的, themeBloc.changeTheme方法来自于源码如下:

import 'package:rxdart/rxdart.dart';

class ThemeChangeBloc {
  bool _isNight = true;

  var _subject = BehaviorSubject<bool>();

  Stream<bool> get isNight => _subject.stream;

  void changeTheme(bool value) => _subject.add(_isNight = value);

  void disposed() {
    _subject.close();
  }
}

我技术比较垃圾,希望您在工作之余闲暇之时为我解惑,不胜感激。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.