我的主要文件在下面;
import 'package:flutter/material.dart';
import 'package:ajanda/screens/mainmenu.dart';
Future<void> main() async{
runApp(MaterialApp(
debugShowCheckedModeBanner: false, title: "Takvim", home: MainMenu()));
}
主菜单文件在下面;
import 'package:ajanda/blocs/theme.dart';
import 'package:provider/provider.dart';
//const String testDevice = 'Mobile_id';
class MainMenu extends StatelessWidget {
MainMenu({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<ThemeChanger>(
builder: (_) => ThemeChanger(ThemeData.dark()),
child: new MaterialAppWithTheme(),
);
}
}
class MaterialAppWithTheme extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MainMenuBody(),
);
}
}
class MainMenuBody extends StatefulWidget {
@override
_MainMenuBodyState createState() => _MainMenuBodyState();
}
class _MainMenuBodyState extends State<MainMenuBody> {
....
}
我正在尝试制作一个黑暗的主题,但我遇到了 2 个错误,我无法解决如果你能提供帮助我会很高兴的原因。我在构建函数中遇到了这样的错误。参数类型“Widget Function (BuildContext)”不能分配给参数类型“Widget Function (BuildContext, Widget)”。像这个错误的另一个问题:返回类型'ThemeChanger'不是'Widget',正如闭包的上下文所要求的那样。
Theme.dart 文件在下面
import 'package:flutter/material.dart';
class ThemeChanger with ChangeNotifier{
ThemeData _themeData;
ThemeChanger(this._themeData);
getTheme() => _themeData;
setTheme(ThemeData theme){
_themeData= theme;
notifyListeners();
}
}