每当用户按下屏幕时,我都会尝试绘制一个小部件。目前我通过存储一个小部件列表来做到这一点,当 ontapup 在手势上被触发时,我将添加到一个小部件列表中。
Widget build(BuildContext context) {
Widget draw = new Text("A");
List<Widget> children = new List<Widget>();
return new Scaffold(
appBar: new AppBar(
title: const Text('Heading'),
leading: new Icon(Icons.question_answer),
),
body: new GestureDetector(
onTapUp: (details) {
setState(() {
children.add(new Positioned(
left: details.globalPosition.dx,
top: details.globalPosition.dy,
child: draw,
));
});
},
child: new Stack(children: children)
...
Run Code Online (Sandbox Code Playgroud)
所以我的代码正在工作,我在单击时绘制小部件,但我的问题是,当添加新的 Positioned() 以堆叠位置时,位置基于不包括 appbar 偏移量的屏幕。有没有办法获得堆栈的初始 x/y 位置?或者有没有办法获得appbars的高度?如何获得小部件的位置或高度/宽度?
我有一个程序从命令行获取用户的输入.令人讨厌的是,当我第一次使用扫描仪时,输入的文本将在下一行(在此之后System.out.println)进行.但是,所有其他时间它与...相同System.out.println.
码:
//Create a scanner
Scanner input = new Scanner(System.in);
//Gets type
System.out.println("--Television Show or Film (t or f): ");
String type = input.nextLine();
input.close();
Run Code Online (Sandbox Code Playgroud)
输出:
--Television Show or Film (t or f):
t
Run Code Online (Sandbox Code Playgroud)
Desierd输出:
--Television Show or Film (t or f): t
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.另外,我正在使用Eclipse Console.
我为我的应用创建了以下主题:
ThemeData _buildDarkTheme() {
final baseTheme = ThemeData(fontFamily: "Sunflower",);
return baseTheme.copyWith(
brightness: Brightness.dark,
primaryColor: Colors.grey[800],
accentColor: Colors.grey[850]);
}
Run Code Online (Sandbox Code Playgroud)
然后我将它应用到我的应用程序,如下所示:
class MyApp extends StatelessWidget {
MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: _buildDarkTheme(),
home: new Scaffold(
appBar: _buildAppBar(),
body: new Container(
color: Theme.of(context).accentColor,
height: double.infinity,
child: new ListView.builder(...
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试访问容器内部(或其他任何地方)的重点颜色而不是预期的Colors.grey [850]时,它默认为蓝色.此外,尝试使用自定义字体向日葵字体系列不起作用,但当我改为使用时
new Text("Hello World", style: new TextStyle(fontFamily: "Sunflower"))
Run Code Online (Sandbox Code Playgroud)
字体显示正确.
我是新手,因为任何解决这些问题的帮助都会受到欢迎.