Open qbait opened 3 years ago
also, change the system theme didn't make the app theme change from light to dark, solution 👉 to use get: 4.3.4 in pubspec.yaml instead of the latest version until the bug fixed
also, change the system theme didn't make the app theme change from light to dark, solution 👉 to use get: 4.3.4 in pubspec.yaml instead of the latest version until the bug fixed
I changed get dependency to 4.3.4 but still not working. I tried few more and I found out that on 4.0.0 it works.
My code:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: Themes.blackTheme,
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
Get.changeTheme(Themes.greenTheme);
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
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.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class Themes {
static ThemeData blackTheme = ThemeData.light().copyWith(
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Colors.grey[800],
));
static ThemeData greenTheme = ThemeData.light().copyWith(
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Colors.green[400],
));
}
any news about this issue? I ended up using providers. It works in mobile simulators but it doesnt in the real device, web, and mac (haven't tried on windows and linux)
I just faced the same issue. Here's a temporary fix if you need:
Get.rootController.darkTheme = _your_dark_theme;
Get.forceAppUpdate();
I've been able to change the theme for light and dark. However, I would like to give the user possibility to choose from any theme (over 10).
I created a sample with the below themes
I'm trying to change my theme in the controller by calling
However, it does not work. I was able to change only between 2 (light and dark).