首页 新闻 会员 周边

请教高手:Flutter 出现Getter no found怎么解决呢?

0
悬赏园豆:10 [已解决问题] 解决于 2021-12-21 10:18

用flutter运行代码的时候出错,错误信息如下:
Launching lib\main.dart on Chrome in debug mode...
org-dartlang-app:/web_entrypoint.dart:13:18: Error: Getter not found: 'main'.
if (entrypoint.main is _UnaryFunction) {
^^^^
org-dartlang-app:/web_entrypoint.dart:14:24: Error: Getter not found: 'main'.
return (entrypoint.main as _UnaryFunction)(<String>[]);
^^^^
org-dartlang-app:/web_entrypoint.dart:16:22: Error: Getter not found: 'main'.
return (entrypoint.main as _NullaryFunction)();
^^^^

Failed to compile application.
Exited (sigterm)

源代码如下:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mysql1/mysql1.dart' as mysql;

class TopMoviePage extends StatefulWidget {
const TopMoviePage({Key? key}) : super(key: key);

@override
_TopMoviePageState createState() => _TopMoviePageState();
}

class _TopMoviePageState extends State<TopMoviePage> {
List movieList = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('电影排行榜'),
),
body: ListView.builder(
itemCount: movieList.length,
itemBuilder: (context, index) => movieCard(index),
),
);
}

Widget movieCard(int index) {
var info = movieList[index];
var imageUrl = movieList[index]['cover_url'].toString();
var movieType = movieList[index]['types'].toString().replaceRange(
movieList[index]['types'].toString().length - 1,
movieList[index]['types'].toString().length,
'');
var movieActors = movieList[index]['actors'].toString().replaceRange(
movieList[index]['actors'].toString().length - 1,
movieList[index]['actors'].toString().length,
'等');
var moviePublicTime;
if (!movieList[index]['release_date'].toString().contains('-')) {
moviePublicTime = movieList[index]['release_date'].toString() + '年';
} else {
moviePublicTime =
movieList[index]['release_date'].toString().replaceFirst('-', '年');
moviePublicTime = moviePublicTime.replaceFirst('-', '月') + '日';
}

return Container(
  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
  margin: EdgeInsets.only(top: 10, left: 8, right: 8),
  decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      boxShadow: [
        BoxShadow(
            color: Color(0xffffffff),
            offset: Offset(0.0, 6.0),
            blurRadius: 0,
            spreadRadius: 0)
      ]),
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Container(
          width: 45,
          height: 20,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.redAccent,
            borderRadius: BorderRadius.all(Radius.circular(3)),
          ),
          child: RichText(
            text: TextSpan(children: [
              TextSpan(
                text: 'No.',
                style: TextStyle(fontSize: 12, color: Colors.white),
              ),
              TextSpan(
                text: info['movie_rank'].toString(),
                style: TextStyle(fontSize: 12, color: Colors.white),
              ),
            ]),
          )),
      SizedBox(
        height: 5,
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 100,
            height: 150,
            child: Image.network(
              imageUrl,
              fit: BoxFit.fill,
            ),
          ),
          SizedBox(
            width: 10,
          ),
          Container(
            // height: 150,
            width: 250,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  info['title'].toString(),
                  style: TextStyle(
                      fontSize: 22,
                      color: Colors.black,
                      fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  height: 10,
                ),
                RichText(
                  text: TextSpan(children: [
                    TextSpan(
                      text: '评分:',
                      style: TextStyle(
                          fontSize: 16,
                          color: Colors.black,
                          fontWeight: FontWeight.w400),
                    ),
                    TextSpan(
                      text: info['score'].toString(),
                      style: TextStyle(fontSize: 16, color: Colors.black),
                    ),
                  ]),
                ),
                RichText(
                  text: TextSpan(children: [
                    TextSpan(
                      text: '时间:',
                      style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w400,
                          color: Colors.black),
                    ),
                    TextSpan(
                      text: moviePublicTime,
                      style: TextStyle(fontSize: 16, color: Colors.black),
                    ),
                  ]),
                ),
                RichText(
                  softWrap: true,
                  text: TextSpan(children: [
                    TextSpan(
                      text: '类型:',
                      style: TextStyle(
                          fontSize: 16,
                          color: Colors.black,
                          fontWeight: FontWeight.w400),
                    ),
                    TextSpan(
                      text: movieType,
                      style: TextStyle(fontSize: 16, color: Colors.black),
                    ),
                  ]),
                ),
                RichText(
                  softWrap: true,
                  text: TextSpan(children: [
                    TextSpan(
                      text: '主演:',
                      style: TextStyle(
                          fontSize: 16,
                          color: Colors.black,
                          fontWeight: FontWeight.w400),
                    ),
                    TextSpan(
                      text: movieActors,
                      style: TextStyle(fontSize: 16, color: Colors.black),
                    ),
                  ]),
                ),
              ],
            ),
          )
        ],
      )
    ],
  ),
);

}

Future Database() async {
//var conn;
var settings = new mysql.ConnectionSettings(
user: "root", //todo:用户名
password: "xxxxxx", //todo:密码
host: "xxxxxxxx", //todo:flutter中电脑本地的ip
port: 3306, //todo:端口
db: "xxxx",
); //todo:需要连接的数据库
var conn = await mysql.MySqlConnection.connect(settings);
var result = await conn.query("select * from home");
await conn.close();
setState(() {
movieList = result.toList();
});
}

@override
void initState() {
super.initState();
Database();
}
}

end

商君治国安邦之张莽的主页 商君治国安邦之张莽 | 初学一级 | 园豆:137
提问于:2021-11-08 12:50
< >
分享
最佳答案
0

已经解决了。谢谢

商君治国安邦之张莽 | 初学一级 |园豆:137 | 2021-12-01 19:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册