THERE ARE 2 ERRORS IN THIS PROGRAM WHICH HAVE BEEN SHOWN IN THE IMAGES ABOVE
Main.dart file
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Personal Expenses ',
theme: ThemeData(
primarySwatch: Colors.green,
accentColor: Colors.amber,
//errorColor: Colors.red[700],
fontFamily: 'Quicksand',
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
fontSize: 18,
),
button: TextStyle(color: Colors.amber)),
appBarTheme: AppBarTheme(
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(
fontFamily: 'OpenSans',
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final List<Transaction> _userTransactions = [
];
bool _showChart = false;
List<Transaction> get _recentTransactions {
return _userTransactions.where((tx) {
return tx.date.isAfter(
DateTime.now().subtract(
Duration(days: 7),
),
);
}).toList();
}
void _addNewTransaction(
String txTitle, double txAmount, DateTime chosenDate) {
final newTx = Transaction(
title: txTitle,
amount: txAmount,
date: chosenDate,
id: DateTime.now().toString(),
);
setState(() {
_userTransactions.add(newTx);
});
}
void _startAddNewTransaction(BuildContext ctx) {
showModalBottomSheet(
context: ctx,
builder: (_) {
return GestureDetector(
onTap: () {},
child: NewTransaction(_addNewTransaction),
behavior: HitTestBehavior.opaque,
);
},
);
}
void _deleteTransaction(String id) {
setState(() {
_userTransactions.removeWhere((tx) => tx.id == id);
});
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final isLandscape = mediaQuery.orientation == Orientation.landscape;
final PreferredSizeWidget appbar = Platform.isIOS
A value of type 'Widget' can't be assigned to a variable of type 'PreferredSizeWidget'.
? CupertinoNavigationBar(
middle: Text(
'Personal Expenses ',
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(CupertinoIcons.add),
onTap: () => _startAddNewTransaction(context),
)
],
),
)
: AppBar(
title: Text(
'Personal Expenses ',
style: TextStyle(fontFamily: 'OpenSans'),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
],
);
final txListWidget = Container(
height: (mediaQuery.size.height -
appbar.preferredSize.height -
mediaQuery.padding.top) *
0.7,
child: TransactionList(
_userTransactions,
_deleteTransaction,
),
);
final pageBody = SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (isLandscape)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Show Chart'),
Switch.adaptive(
activeColor: Theme.of(context).accentColor,
value: _showChart,
onChanged: (val) {
setState(() {
_showChart = val;
});
},
),
],
),
],
),
);
return Platform.isIOS ? CupertinoPageScaffold( child: pageBody, navigationBar: appbar,
The argument type 'PreferredSizeWidget' can't be assigned to the parameter type 'ObstructingPreferredSizeWidget?'.
)
: Scaffold(
.........,
),
);
}
}

