The following error occurred while cloning Instagram. If the if statement is removed, the output is normal, but if an if statement is added, an error occurs. I can't get a hold of it at all.
The error message as below. Class 'bool' has no instance method 'call'. Receiver: true Tried calling: call()
My code is below.
import 'package:flutter/material.dart';
import './style.dart' as style;
import 'package:http/http.dart' as http;
import 'dart:convert';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: style.theme,
home: MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var tab = 1;
var data = [];
getData() async {
var result = await http.get(
Uri.parse('https://codingapple1.github.io/app/data.json'),
);
var result2 = jsonDecode(result.body); //jsonDecode(): json을 list나 map자료로 변환
setState(() {
data = result2;
});
}
@override
void initState() {
super.initState();
getData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Instagram',
),
actions: [
IconButton(
icon: Icon(Icons.add_box_outlined),
onPressed: () {},
iconSize: 30,
),
],
),
body: Home(data: data),
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
onTap: (i) {
setState(() {
tab = i;
});
},
items: [
BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: '홈'),
BottomNavigationBarItem(
icon: Icon(Icons.shopping_bag_outlined), label: '샵'),
],
),
);
}
}
class Home extends StatelessWidget {
const Home({Key? key, this.data}) : super(key: key);
final data;
@override
Widget build(BuildContext context) {
if (data.isNotEmpty()) {
return ListView.builder(
itemCount: 3,
itemBuilder: (context, index) {
return SizedBox(
height: 380,
child: Column(
children: [
Image.network(data[index]['image'], width: 300),
SizedBox(
width: 300,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'좋아요 ${data[index]['likes']}',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(data[index]['user']),
Text(data[index]['content']),
],
),
)
],
),
);
},
);
} else {
return Text('로딩중임');
}
}
}
