首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在null上调用了getter 'navigator‘

在null上调用了getter 'navigator‘
EN

Stack Overflow用户
提问于 2018-06-22 04:35:14
回答 1查看 1.5K关注 0票数 2

从今天早上开始我就收到了这个错误,在查看了堆栈跟踪之后,我已经将这个错误追溯到了runApp方法,我一点也不明白问题是什么,如果有任何帮助,我将不胜感激:)这是一个例外:在null上调用了getter 'navigator‘

这里是我的main.dart文件

代码语言:javascript
复制
import 'dart:async';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart';
import 'package:savings/utils/analytics.dart';
import 'package:savings/utils/colors.dart';
import 'package:savings/pages/goals_page.dart';
import 'package:savings/utils/logic.dart' as AppLogic;
import 'package:savings/utils/models.dart' as models;
import 'package:savings/utils/variables.dart';
import 'package:flutter/services.dart';

void main() => runApp(new SavingsApp());

class SavingsApp extends StatefulWidget {
 @override
 _SavingsAppState createState() => new _SavingsAppState();
}

class _SavingsAppState extends State<SavingsApp> {
 @override
 void initState() {
 initAppData();
 super.initState();
}

 @override
 Widget build(BuildContext context) {
  return new MaterialApp(
  debugShowCheckedModeBanner: false,
  title: 'Savings',
  color: primaryThemeColor,
  home: GoalsPage(),
  navigatorObservers: <NavigatorObserver>[analyticsObserver],
  theme: new ThemeData(
    primaryColor: primaryThemeColor,
    accentColor: accentThemeColor,
    fontFamily: "Proxima Nova",
  ),
);
}

@override
void dispose() {
 //Good practice to close the DB
 AppLogic.DatabaseInterface.closeDB();

//Handle orientation
SystemChrome.setPreferredOrientations([
  DeviceOrientation.landscapeRight,
  DeviceOrientation.landscapeLeft,
  DeviceOrientation.portraitUp,
  DeviceOrientation.portraitDown,
]);
super.dispose();
}

 Future<Null> initAppData() async {

//Database
_initDBData();

//Analytics
analytics = new FirebaseAnalytics();
AnalyticsInterface.logAppOpen();
analyticsObserver = new FirebaseAnalyticsObserver(analytics: analytics);
  }

  Future<Null> _initDBData() async {
   //Orientation
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);

//Retrieve database from the DB interface
appDatabase = await AppLogic.DatabaseInterface.getDB();

//Log output
print("DatabaseInterface: DatabaseInitiated");

//Get a local version of the lists after the DB has been initiated
List<models.Goal> _goalsList =
    await AppLogic.DatabaseInterface.getAllGoalsFromDB();

List<models.Transaction> _transactionsList =
    await AppLogic.DatabaseInterface.getAllTransactionsFromDB();

//Call setState and update the global lists (which are used in the whole app) from the local ones
setState(() {
  allGoalsList = _goalsList;
  allTransactionsList = _transactionsList;
    });
  }
}

日志目录

代码语言:javascript
复制
The following NoSuchMethodError was thrown building 
DefaultTextStyle(debugLabel: fallback style;
I/flutter ( 4211): consider putting your text in a Material, inherit: true, 
color: Color(0xd0ff0000), family:
I/flutter ( 4211): monospace, size: 48.0, weight: 900, decoration: double 
Color(0xffffff00) TextDecoration.underline,   
I/flutter ( 4211): softWrap: wrapping at box width, overflow: clip):
I/flutter ( 4211): The getter 'navigator' was called on null.
I/flutter ( 4211): Receiver: null
I/flutter ( 4211): Tried calling: navigator
I/flutter ( 4211): 
I/flutter ( 4211): When the exception was thrown, this was the stack:
I/flutter ( 4211): #0      Object.noSuchMethod 
(dart:core/runtime/libobject_patch.dart:46:5)
I/flutter ( 4211): #1      NavigatorState.initState 
(package:flutter/src/widgets/navigator.dart:1303:23)
I/flutter ( 4211): #2      StatefulElement._firstBuild 
(package:flutter/src/widgets/framework.dart:3751:58)
I/flutter ( 4211): #3      ComponentElement.mount 
(package:flutter/src/widgets/framework.dart:3617:5)
...
...
I/flutter ( 4211): #104    runApp (package:flutter/src/widgets/binding.dart:704:7)
I/flutter ( 4211): #105    main (file:///C:/Coding/savings/lib/main.dart:13:16)
I/flutter ( 4211): #106    _startIsolate.<anonymous closure (dart:isolate/runtime/libisolate_patch.dart:279:19)
I/flutter ( 4211): #107    _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50977041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档