I got this error on terminal
lib/pages/pomodoro.dart:31:21: Error: This expression has type 'void' and can't be used. ? null ^
This is my code:
import 'package:braintrinig/components/cronometro.dart';
import 'package:braintrinig/components/entrada_tempo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:provider/provider.dart';
import '../pages/pomodoro.store.dart';
import 'package:braintrinig/pages/pomodoro.store.dart';
class Pomodoro extends StatelessWidget {
const Pomodoro({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final store = Provider.of<PomodoroStore>(context);
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: Cronometro(),
),
Padding(padding: EdgeInsets.symmetric(vertical: 40),
child: Observer(
builder: (_) => Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
EntradaTempo(
titulo: 'Work',
valor: store.tempoWork,
inc: store.start && store.isWorking()
? null
: store.incrementarTempoWork(),
dec: store.reduceTempoRest,
),
EntradaTempo(
titulo: 'Relax',
valor: store.tempoRest,
inc: store.incrementarTempoRest,
dec: store.reduceTempoRest,
),
],
),
)
),
],
),
);
}
}
The error is here:
How to solve this issue?
Thank you in advance
CodePudding user response:
This is probably due to the fact that either store.start
or store.incrementarTempoWork()
is not returnning a value and this is void
.
Also check that inc
accepts null
.
inc: store.start && store.isWorking()
? null
: store.incrementarTempoWork(), // <<<< probably this one is void
CodePudding user response:
In dart while checking conditions the value used to compare must not be null after upgrade to Null Safety. so you have to confirm it with ! symbol.
! symbol tells to compiler that particular field have data...
may be below one work.
inc: store!.start! && store!.isWorking()
? null
: store!.incrementarTempoWork(),