對于一個簡單的設計,我想在 Flutter 專案中快速實作 ElevatedButton,但 Flutter 根本找不到 ElevatedButton。我唯一找到的是 ElevatedButtonTheme,如果我手動輸入 ElevatedButton(包括子元素和 onPressed),則名稱將被視為錯誤。

我做錯了嗎?除了import 'package:flutter/material.dart';"
這里是源代碼:
import 'package:flutter/material.dart';
class LandingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
appBar: AppBar(
backgroundColor: Colors.grey[300],
title: Image.asset(
'assets/images/logo.png',
fit: BoxFit.contain,
height: 40,
),
centerTitle: true,
elevation: 0,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(50.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Quest 01 | 2022',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.normal
),
),
ElevatedButton(
onPressed: () {},
child: const Text('Example'),
),
],
),
),
),
);
}
}
錯誤資訊是:
lib/pages/landingpage.dart:33:15:錯誤:沒有為類“LandingPage”定義方法“ElevatedButton”。
- “LandingPage”來自“package:eumood/pages/landingpage.dart”(“lib/pages/landingpage.dart”)。嘗試將名稱更正為現有方法的名稱,或定義名為“ElevatedButton”的方法。高架按鈕(^^^^^^^^^^^^^^
謝謝你的幫助最好的,克里斯
uj5u.com熱心網友回復:
你能展示你的進口嗎,否則你能在沒有自動完成的情況下使用這個例子嗎
ElevatedButton(
onPressed: () {},
child: const Text('Example'),
),
uj5u.com熱心網友回復:
嘗試不使用自動完成,
ElevatedButton(
onPressed: (){},
child: Text("Elevated Button")
),
uj5u.com熱心網友回復:
好的,我為我的問題找到了一個(相當激進的)解決方案。我更新了我的 kotlin 版本和依賴項。我不確定這是解決方案,或者可能還有其他問題,但至少它對我有用。
我更改了 [projectname]/android/build.gradle中的引數
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
檔案可以在這里找到
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/522053.html
標籤:扑按钮
