title: Flutter: programmatically cause darkTheme to be used
body: <p>In Flutter, you can set a dark theme to be used, which will be used if certain contexts (e.g. Dark Mode is set on Android Q). Is there a recommended way to allow that to be overridden  programmatically; e.g, in response to a user preference?</p>
  
  <p>I guess this could be done at the very top level of the app:</p>
  
  <pre><code>MaterialApp(
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      themeMode: fromSomeState,
  )
  </code></pre>
  
  <p>However, I'd also like to be able switch on whether or not the app is in dark mode programmatically at various points in the app (e.g. for image selection):</p>
  
  <pre><code>MediaQuery.of(context).platformBrightness == Brightness.dark;
  </code></pre>
  
  <p>I could try and update the <code>MediaQueryData</code> to override <code>platformBrightness</code> as well, but that can only be done inside <code>MaterialApp</code>, which seems awkward. </p>
  
  <p>Is there a better pattern for doing this kind of thing?</p>