【发布时间】:2018-10-04 13:44:46
【问题描述】:
我开始学习颤振/飞镖,并坚持使用基本打印。
我有一些通过 Android Studio 运行的基本应用程序。
我注意到,我可以在 myLocationApp 类中使用“print”和“debugPrint”,但不能在 myTestLocation 类中使用。
如果我尝试使用
print( myTestString );
错误是
compiler message: lib/main.dart:8:7: Error: The non-abstract class 'MyTestLocation' is missing implementations for these members:
compiler message: 'print'.
当我在线搜索例如here 时,它没有提到任何这些,所以我在这里缺少的主要本质是什么,我猜我需要修改类以包含/引用打印?但不确定最好的方法是什么。
import 'package:flutter/material.dart';
import 'package:location/location.dart';
import 'package:flutter/foundation.dart';
void main() => runApp(new MyLocationApp());
class MyTestLocation {
String myTestString = "Testing2";
print( myTestString ); // No implentation error here
}
class MyLocationApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
final location = new MyTestLocation();
debugPrint( location.toString() );
return new MaterialApp(
title: 'Welcome',
home: new Scaffold(
appBar: new AppBar(
title: new Text('appBarTitle'),
),
body: new Center(
child: new Text( location.myTestString ),
)
),
);
}
}
【问题讨论】: