【问题标题】:Flutter ListTile onTap function doesn't redirect to new pageFlutter ListTile onTap 函数不会重定向到新页面
【发布时间】:2021-02-06 13:53:48
【问题描述】:

我制作了一个列表图块,但 onTap 函数没有重定向到新的 dart 页面。它在我以前的程序中有效,但现在不行。你能让我走上正确的道路吗?我不明白我的代码有什么问题。我只希望当用户单击平铺时,它会重定向到相关或分配的 dart 文件。例如:Kargo 应该重定向到 kargo.dart。

import 'package:flutter/material.dart';
import 'kargo.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Akçakale Sarı Sayfa',
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Akçakale Sarı Sayfa'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title,
            style: TextStyle(color: Colors.amberAccent, fontSize: 24)),
        backgroundColor: Colors.black87,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.circular(20),
          ),
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Card(
              child: ListTile(
                  leading: const Icon(
                    Icons.directions_bus,
                    color: Colors.white,
                  ),
                  title: Text(
                    'Kargo',
                    style: TextStyle(color: Colors.amberAccent),
                  ),
                  tileColor: Colors.black87,
                  onTap: () {
                    Navigator.push(context,
                        new MaterialPageRoute(builder: (context) => new kargo()));
                  }),
            ),

【问题讨论】:

  • 您是否遇到任何错误?如果没有,请分享Kargo的代码。

标签: flutter


【解决方案1】:

谢谢你,我解决了这个错误。我刚刚将 Kargo 作为类分配到新页面

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 2021-07-21
    • 1970-01-01
    • 2019-06-30
    • 2015-09-06
    • 1970-01-01
    • 2017-10-26
    • 2019-03-09
    • 1970-01-01
    相关资源
    最近更新 更多