import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
highContrastTheme: ThemeData.dark(),
highContrastDarkTheme: ThemeData.light(),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
bool _switchValues = false;
void _incrementCounter() {
setState(() {
_counter++;
_switchValues = !_switchValues;
});
}
@override
Widget build(BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
highContrast: _switchValues,
invertColors: _switchValues,
boldText: _switchValues,
disableAnimations: _switchValues,
),
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}
Changing the values of
highContrast,invertColors, and maybedisableAnimations, in aMediaQuerydoes not affect the app.I am not sure how to test
disableAnimations, in another project I created some animations and set the simulator to Reduce motion but I could not see any difference, so I am not sure how I could test this.Note that
boldText, which is set inMediaQueryin the same way, works as expected (see below).Steps to Reproduce
flutter create bug.darkTheme,highContrastTheme, andhighContrastDarkThemeto theMaterialApp. For instance:bool _switchValues = false;property to_MyHomePageState._switchValues = !_switchValues;to thesetStatein_incrementCounter().Scaffoldwith aMediaQuerywithdata:Expected results:
Actual results:
Logs
Full code