Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 为什么在更改应用程序的主题时生成函数会出错?_Flutter_Flutter Theme - Fatal编程技术网

Flutter 为什么在更改应用程序的主题时生成函数会出错?

Flutter 为什么在更改应用程序的主题时生成函数会出错?,flutter,flutter-theme,Flutter,Flutter Theme,我的主要文件如下 import 'package:flutter/material.dart'; import 'package:ajanda/screens/mainmenu.dart'; Future<void> main() async{ runApp(MaterialApp( debugShowCheckedModeBanner: false, title: "Takvim", home: MainMenu())); } import '

我的主要文件如下

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> {

....

}

您需要遵循这些步骤

import 'package:flutter/material.dart';

final darkTheme = ThemeData(
 primarySwatch: Colors.grey,
 primaryColor: Colors.black,
 brightness: Brightness.dark,
 backgroundColor: const Color(0xFF212121),
 accentColor: Colors.white,
 accentIconTheme: IconThemeData(color: Colors.black),
 dividerColor: Colors.black12,
);
    
 
final lightTheme = ThemeData(
 primarySwatch: Colors.grey,
primaryColor: Colors.white,
brightness: Brightness.light,
backgroundColor: const Color(0xFFE5E5E5),
accentColor: Colors.black,
accentIconTheme: IconThemeData(color: Colors.white),
dividerColor: Colors.white54,
 );
提供者类

import 'package:flutter/material.dart';

class ThemeNotifier with ChangeNotifier {
  ThemeData _themeData;

  ThemeNotifier(this._themeData);

  getTheme() => _themeData;

  setTheme(ThemeData themeData) async {
    _themeData = themeData;
    notifyListeners();
  }
}

void main() => runApp(
  ChangeNotifierProvider<ThemeNotifier>(
    builder: (_) => ThemeNotifier(darkTheme),
    child: MyApp(),
  ),
);

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 final themeNotifier = Provider.of<ThemeNotifier>(context);
 return MaterialApp(
   title: 'Chitr',
  theme: themeNotifier.getTheme(),
  home: HomePage(),
);
 }
 }
导入“包装:颤振/材料.省道”;
使用ChangeNotifier对消息过滤器进行分类{
主题数据;
主题化器(本主题数据);
getTheme()=>\u主题数据;
setTheme(主题数据主题数据)异步{
_主题数据=主题数据;
notifyListeners();
}
}
void main()=>runApp(
变更通知提供者(
建造商:()=>ThemeNotifier(暗色),
子项:MyApp(),
),
);
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
final themeNotifier=Provider.of(上下文);
返回材料PP(
标题:“Chitr”,
主题:themeNotifier.getTheme(),
主页:主页(),
);
}
}

您需要遵循以下步骤

import 'package:flutter/material.dart';

final darkTheme = ThemeData(
 primarySwatch: Colors.grey,
 primaryColor: Colors.black,
 brightness: Brightness.dark,
 backgroundColor: const Color(0xFF212121),
 accentColor: Colors.white,
 accentIconTheme: IconThemeData(color: Colors.black),
 dividerColor: Colors.black12,
);
    
 
final lightTheme = ThemeData(
 primarySwatch: Colors.grey,
primaryColor: Colors.white,
brightness: Brightness.light,
backgroundColor: const Color(0xFFE5E5E5),
accentColor: Colors.black,
accentIconTheme: IconThemeData(color: Colors.white),
dividerColor: Colors.white54,
 );
提供者类

import 'package:flutter/material.dart';

class ThemeNotifier with ChangeNotifier {
  ThemeData _themeData;

  ThemeNotifier(this._themeData);

  getTheme() => _themeData;

  setTheme(ThemeData themeData) async {
    _themeData = themeData;
    notifyListeners();
  }
}

void main() => runApp(
  ChangeNotifierProvider<ThemeNotifier>(
    builder: (_) => ThemeNotifier(darkTheme),
    child: MyApp(),
  ),
);

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 final themeNotifier = Provider.of<ThemeNotifier>(context);
 return MaterialApp(
   title: 'Chitr',
  theme: themeNotifier.getTheme(),
  home: HomePage(),
);
 }
 }
导入“包装:颤振/材料.省道”;
使用ChangeNotifier对消息过滤器进行分类{
主题数据;
主题化器(本主题数据);
getTheme()=>\u主题数据;
setTheme(主题数据主题数据)异步{
_主题数据=主题数据;
notifyListeners();
}
}
void main()=>runApp(
变更通知提供者(
建造商:()=>ThemeNotifier(暗色),
子项:MyApp(),
),
);
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
final themeNotifier=Provider.of(上下文);
返回材料PP(
标题:“Chitr”,
主题:themeNotifier.getTheme(),
主页:主页(),
);
}
}