For a simple design I wanted quickly implement a ElevatedButton in a Flutter project but Flutter does not find the ElevatedButton at all. The only thing I find is the ElevatedButtonTheme and if I type in the ElevatedButton manually (incl. the child and onPressed) the name is maked as an error.
Do I do something wrong? Do I need to include something extra other than the import 'package:flutter/material.dart';"
Here the source code:
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'),
),
],
),
),
),
);
}
}
The error message is:
lib/pages/landingpage.dart:33:15: Error: The method 'ElevatedButton' isn't defined for the class 'LandingPage'.
- 'LandingPage' is from 'package:eumood/pages/landingpage.dart' ('lib/pages/landingpage.dart'). Try correcting the name to the name of an existing method, or defining a method named 'ElevatedButton'. ElevatedButton( ^^^^^^^^^^^^^^
Thanks for you help Best, Chris
CodePudding user response:
can you show your imports please else can you use this example without auto complete
ElevatedButton(
onPressed: () {},
child: const Text('Example'),
),
CodePudding user response:
Try without using AutoComplete,
ElevatedButton(
onPressed: (){},
child: Text("Elevated Button")
),
CodePudding user response:
Ok I figured out a (quite radical) solution for my problem. I updated my kotlin version and the dependencies. I'm not sure this is the solution or maybe there was something else wrong but at least it did the trick for me.
I changed the parameters in [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"
}
}
The documentation can be found here