Olá, boa tarde!
Segui o passo a passo do professor, porém, ao realizar o teste de envio, estou recebendo o seguinte erro no terminal do servidor:
SyntaxError: Unexpected token c in JSON at position 0
at JSON.parse (<anonymous>)
at file:///C:/Users/thiag/AppData/Roaming/npm/node_modules/json-server/node_modules/milliparsec/dist/index.js:21:45
at file:///C:/Users/thiag/AppData/Roaming/npm/node_modules/json-server/node_modules/milliparsec/dist/index.js:8:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///C:/Users/thiag/AppData/Roaming/npm/node_modules/json-server/node_modules/milliparsec/dist/index.js:21:20
at async file:///C:/Users/thiag/AppData/Roaming/npm/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:169:7
at async file:///C:/Users/thiag/AppData/Roaming/npm/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:434:7
Aqui está o trecho do código jornal_service.dart:
import 'package:http/http.dart' as http;
class JournalService {
static const String url = 'http://172.30.1.46:3000/';
static const String resource = 'learnhttp/';
String getUrl() {
return '$url$resource';
}
register(String content) {
http.post(Uri.parse(getUrl()), body: {"content": content});
}
}
E o trecho do código main.dart:
import 'package:flutter/material.dart';
import 'package:flutter_webapi_first_course/services/jornal_service.dart';
import 'package:google_fonts/google_fonts.dart';
import 'screens/home_screen/home_screen.dart';
void main() {
runApp(const MyApp());
JournalService service = JournalService();
service.register("Olá Mundo!");
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Simple Journal',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
appBarTheme: const AppBarTheme(
elevation: 0,
backgroundColor: Colors.black,
titleTextStyle: TextStyle(color: Colors.white),
),
textTheme: GoogleFonts.bitterTextTheme(),
),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.light,
initialRoute: "home",
routes: {
"home": (context) => const HomeScreen(),
},
);
}
}