══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _TypeError was thrown building Builder:
type ‘Color’ is not a subtype of type ‘MaterialColor’
The relevant error-causing widget was:
MaterialApp file:///D:/FlutterExercise/FlutterExercise/07/spanishaudioplayer/lib/main.dart:9:12
When the exception was thrown, this was the stack:
#0 new _HomePageState (package:spanishaudioplayer/HomePage.dart:22:35)
#1 HomePage.createState (package:spanishaudioplayer/HomePage.dart:7:35)
#2 new StatefulElement (package:flutter/src/widgets/framework.dart:4584:24)
#3 StatefulWidget.createElement (package:flutter/src/widgets/framework.dart:916:38)
… Normal element mounting (166 frames)
#169 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#170 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6094:32)
… Normal element mounting (300 frames)
#470 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#471 Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18)
#472 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16)
#473 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1153:5)
#474 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1095:18)
#475 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2647:19)
#476 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1094:13)
#477 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:934:7)
#478 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:915:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════════════════════════
W/InputMethodManager(14486): startInputReason = 8
W/IInputConnectionWrapper(14486): getExtractedText on inactive InputConnection
W/IInputConnectionWrapper(14486): getTextBeforeCursor on inactive InputConnection
V/ActivityThread(14486): Finishing stop of ActivityRecord{801579c token=android.os.BinderProxy@63e470c {com.example.spanishaudioplayer/com.example.spanishaudioplayer.MainActivity}}
W/libEGL (14486): EGLNativeWindowType 0x76efee7010 disconnect failed
W/libEGL (14486): EGLNativeWindowType 0x7713667010 disconnect failed
V/ActivityThread(14486): Handle window ActivityRecord{801579c token=android.os.BinderProxy@63e470c {com.example.spanishaudioplayer/com.example.spanishaudioplayer.MainActivity}} visibility: false
/////////////////////////////////////////////////////////////////////////////////////////////////////
//main.dart
import 'package:flutter/material.dart';
import 'HomePage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Spanish Audio Numbers',
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: HomePage(),
);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//HomePage.dart
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
import 'NumberAudio.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
AudioCache audioPlayer = AudioCache();
List<NumberAudio> audioList = (
NumberAudio("one.wav", Colors.red, "one"),
NumberAudio("two.wav", Colors.blue, "two"),
NumberAudio("three.wav", Colors.pink, "three"),
NumberAudio("four.wav", Colors.orange, "four"),
NumberAudio("five.wav", Colors.purple, "five"),
NumberAudio("six.wav", Colors.cyan, "six"),
NumberAudio("seven.wav", Colors.green, "seven"),
NumberAudio("eight.wav", Colors.grey, "eight"),
NumberAudio("nine.wav", Colors.yellow, "nine"),
NumberAudio("ten.wav", Colors.black, "ten"),
);
play(String audioFile) async {
audioPlayer.play(audioFile);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Spanish Numbers',
style: TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
//backgroundColor: Colors.teal,
),
body: Center(
child: Column(
children: (
Image(
image: AssetImage("images/logo.png"),
),
Expanded(
child: GridView.builder(
padding: EdgeInsets.all(10.0),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 1.0,
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemCount: audioList.length,
itemBuilder: (context, index) => SizedBox(
height: 50.0,
width: 100.0,
child: RaisedButton(
child: Text(
audioList(index).buttonTitle,
style: TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
color: audioList(index).buttonColor,
onPressed: () {
play(audioList(index).audioFile);
},
),
),
),
),
),
),
),
);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//NumberAudio.dart
import 'package:flutter/material.dart';
class NumberAudio {
String audioFile;
MaterialColor buttonColor;
String buttonTitle;
NumberAudio(String audioFile, MaterialColor buttonColor, String buttonTitle) {
this.audioFile = audioFile;
this.buttonColor = buttonColor;
this.buttonTitle = buttonTitle;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
audio files are in the assets folder and the logo is in images folder.