diff --git a/lib/helpers/db_helper.dart b/lib/helpers/db_helper.dart index 0740e3b..a1f7edd 100644 --- a/lib/helpers/db_helper.dart +++ b/lib/helpers/db_helper.dart @@ -21,7 +21,7 @@ class DBHelper { ); } - static Future insert(String table, Map data) async { + static Future insert(String table, Map data) async { final db = await DBHelper.database(); return db.insert( table, @@ -30,10 +30,10 @@ class DBHelper { ); } - static Future update( + static Future update( String table, String column, - String id, + String? id, dynamic data, ) async { final db = await DBHelper.database(); @@ -46,7 +46,7 @@ class DBHelper { String column, int oldIndex, int newIndex, [ - String groupingColStr = '', + String? groupingColStr = '', String groupingCol = '', ]) async { final db = await DBHelper.database(); @@ -78,7 +78,7 @@ class DBHelper { ); } - static Future reorderGroupedBy( + static Future reorderGroupedBy( String table, String column, String groupingColVal, @@ -101,15 +101,15 @@ class DBHelper { ); } - static Future delete(String table, String id) async { + static Future delete(String table, String? id) async { final db = await DBHelper.database(); return db.rawDelete('DELETE FROM $table WHERE id = ?', [id]); } - static Future>> getData( + static Future>> getData( String table, [ String column = '', - String id = '', + String? id = '', ]) async { final db = await DBHelper.database(); if (id == '' || column == '') { diff --git a/lib/main.dart b/lib/main.dart index 69ded22..dea7e01 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,15 +26,15 @@ final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = final BehaviorSubject didReceiveLocalNotificationSubject = BehaviorSubject(); -final BehaviorSubject selectNotificationSubject = - BehaviorSubject(); +final BehaviorSubject selectNotificationSubject = + BehaviorSubject(); class ReceivedNotification { ReceivedNotification({ - @required this.id, - @required this.title, - @required this.body, - @required this.payload, + required this.id, + required this.title, + required this.body, + required this.payload, }); final int id; @@ -43,12 +43,12 @@ class ReceivedNotification { final String payload; } -String selectedNotificationPayload; +String? selectedNotificationPayload; // String _initialRoute; void main() async { WidgetsFlutterBinding.ensureInitialized(); - Workmanager.initialize( + Workmanager().initialize( callbackDispatcher, ); @@ -70,7 +70,7 @@ void main() async { ); await flutterLocalNotificationsPlugin.initialize(initializationSettings, - onSelectNotification: (String payload) async { + onSelectNotification: (String? payload) async { if (payload != null) { debugPrint('notification payload: $payload'); } @@ -187,12 +187,12 @@ Future _fetchStartupData(BuildContext context) async { void _setDailyQuoteNotification(BuildContext context) async { if (Provider.of(context, listen: false) - .receiveQuoteNotifs) { - Workmanager.registerPeriodicTask( + .receiveQuoteNotifs!) { + Workmanager().registerPeriodicTask( 'quote-notification', 'quote-notification', inputData: { - 'locale': AppLocalizations.of(context).localeName, + 'locale': AppLocalizations.of(context)!.localeName, }, frequency: Duration(days: 1), existingWorkPolicy: ExistingWorkPolicy.keep, @@ -205,26 +205,26 @@ void _setDailyQuoteNotification(BuildContext context) async { ), ); } else { - Workmanager.cancelByUniqueName('quote-notification'); + Workmanager().cancelByUniqueName('quote-notification'); } } void callbackDispatcher() { - Workmanager.executeTask((taskName, inputData) async { + Workmanager().executeTask((taskName, inputData) async { switch (taskName) { case 'progress-notification': final addictionData = - await DBHelper.getData('addictions', 'id', inputData['id']); + await DBHelper.getData('addictions', 'id', inputData!['id']); final addiction = Addiction( - id: addictionData[0]['id'], - name: addictionData[0]['name'], - quitDate: addictionData[0]['quit_date'], - consumptionType: addictionData[0]['consumption_type'], - dailyConsumption: addictionData[0]['daily_consumption'], - unitCost: addictionData[0]['unit_cost'], - level: addictionData[0]['level'], + id: addictionData[0]['id'] as String, + name: addictionData[0]['name'] as String, + quitDate: addictionData[0]['quit_date'] as String, + consumptionType: addictionData[0]['consumption_type'] as int, + dailyConsumption: addictionData[0]['daily_consumption'] as double, + unitCost: addictionData[0]['unit_cost'] as double, + level: addictionData[0]['level'] as int?, ); - final nextLevel = addiction.level + 1; + final nextLevel = addiction.level! + 1; if (addiction.abstinenceTime.inSeconds >= levelDurations[nextLevel].inSeconds) { await DBHelper.update( @@ -240,11 +240,11 @@ void callbackDispatcher() { } // if last achievement level, cancel if (addiction.level == 8) { - Workmanager.cancelByUniqueName(addiction.id); + Workmanager().cancelByUniqueName(addiction.id); } break; case 'quote-notification': - final quoteList = quotes[inputData['locale']]; + final quoteList = quotes[inputData!['locale']]!; Random random = new Random(DateTime.now().millisecondsSinceEpoch); int rndi = random.nextInt(quoteList.length); showQuoteNotification( @@ -276,7 +276,8 @@ void showProgressNotification( ); } -void showQuoteNotification(String notificationTitle, String notificationBody) { +void showQuoteNotification( + String? notificationTitle, String? notificationBody) { final androidDetails = AndroidNotificationDetails( 'quitAllProgress', 'progressNotifications', diff --git a/lib/models/addiction.dart b/lib/models/addiction.dart index b5c4d31..f942f35 100644 --- a/lib/models/addiction.dart +++ b/lib/models/addiction.dart @@ -12,19 +12,19 @@ class Addiction { final int consumptionType; final double dailyConsumption; final double unitCost; - List personalNotes; - List gifts; - int level; - int achievementLevel; - int sortOrder; + List? personalNotes; + List? gifts; + int? level; + int? achievementLevel; + int? sortOrder; Addiction({ - @required this.id, - @required this.name, - @required this.quitDate, - @required this.consumptionType, - @required this.dailyConsumption, - @required this.unitCost, + required this.id, + required this.name, + required this.quitDate, + required this.consumptionType, + required this.dailyConsumption, + required this.unitCost, this.personalNotes, this.gifts, this.level, @@ -56,8 +56,8 @@ class Addiction { double get totalSpent { double total = 0.0; - gifts.forEach((gift) { - total += gift.price * gift.count; + gifts!.forEach((gift) { + total += gift.price! * gift.count!; }); return total; } @@ -67,9 +67,9 @@ class Addiction { } List get personalNotesDateSorted { - List list = [...personalNotes]; + List list = [...personalNotes!]; list.sort((a, b) { - return DateTime.parse(b.date).compareTo(DateTime.parse(a.date)); + return DateTime.parse(b.date!).compareTo(DateTime.parse(a.date!)); }); return list; } diff --git a/lib/models/gift.dart b/lib/models/gift.dart index 684ddc1..351183e 100644 --- a/lib/models/gift.dart +++ b/lib/models/gift.dart @@ -1,20 +1,20 @@ import 'package:flutter/foundation.dart'; class Gift { - final String id; - final String addictionId; - final String name; - final double price; - int sortOrder; - int count; + final String? id; + final String? addictionId; + final String? name; + final double? price; + int? sortOrder; + int? count; Gift({ - @required this.id, - @required this.addictionId, - @required this.name, - @required this.price, - @required this.sortOrder, - int count, + required this.id, + required this.addictionId, + required this.name, + required this.price, + required this.sortOrder, + int? count, }) { this.count = count ?? 0; } diff --git a/lib/models/personal_note.dart b/lib/models/personal_note.dart index a1aef48..297e697 100644 --- a/lib/models/personal_note.dart +++ b/lib/models/personal_note.dart @@ -1,13 +1,13 @@ import 'package:flutter/foundation.dart'; class PersonalNote { - final String title; - final String text; - final String date; + final String? title; + final String? text; + final String? date; PersonalNote({ - @required this.title, - @required this.text, - @required this.date, + required this.title, + required this.text, + required this.date, }); } diff --git a/lib/providers/addictions_provider.dart b/lib/providers/addictions_provider.dart index 0b5fb60..589ed35 100644 --- a/lib/providers/addictions_provider.dart +++ b/lib/providers/addictions_provider.dart @@ -17,7 +17,7 @@ class AddictionsProvider with ChangeNotifier { if (addiction.sortOrder == _addictions.length) _addictions.add(addiction); else - _addictions.insert(addiction.sortOrder, addiction); + _addictions.insert(addiction.sortOrder!, addiction); notifyListeners(); await DBHelper.insert( @@ -34,7 +34,7 @@ class AddictionsProvider with ChangeNotifier { 'sort_order': _addictions.length, }, ); - reorderAddictions(_addictions.length, addiction.sortOrder); + reorderAddictions(_addictions.length, addiction.sortOrder!); } Future createAddiction(Map data) async { @@ -85,15 +85,15 @@ class AddictionsProvider with ChangeNotifier { addictionsTable.forEach( (addiction) async { var temp = Addiction( - id: addiction['id'], - name: addiction['name'], - quitDate: addiction['quit_date'], - consumptionType: addiction['consumption_type'], - dailyConsumption: addiction['daily_consumption'], - unitCost: addiction['unit_cost'], - level: addiction['level'], - achievementLevel: addiction['achievement_level'], - sortOrder: addiction['sort_order'], + id: addiction['id'] as String, + name: addiction['name'] as String, + quitDate: addiction['quit_date'] as String, + consumptionType: addiction['consumption_type'] as int, + dailyConsumption: addiction['daily_consumption'] as double, + unitCost: addiction['unit_cost'] as double, + level: addiction['level'] as int?, + achievementLevel: addiction['achievement_level'] as int?, + sortOrder: addiction['sort_order'] as int?, personalNotes: [], gifts: [], ); @@ -102,7 +102,7 @@ class AddictionsProvider with ChangeNotifier { }, ); loadedAddictions.sort((a, b) { - return a.sortOrder.compareTo(b.sortOrder); + return a.sortOrder!.compareTo(b.sortOrder!); }); _addictions = loadedAddictions; notifyListeners(); @@ -113,9 +113,9 @@ class AddictionsProvider with ChangeNotifier { final addiction = _addictions.firstWhere((addiction) => addiction.id == id); _addictions.remove(addiction); notifyListeners(); - final temp = _addictions.where((a) => a.sortOrder > addiction.sortOrder); + final temp = _addictions.where((a) => a.sortOrder! > addiction.sortOrder!); temp.forEach((a) async { - a.sortOrder--; + a.sortOrder = a.sortOrder! - 1; await DBHelper.update('addictions', 'sort_order', a.id, a.sortOrder); }); await DBHelper.delete('addictions', id); @@ -140,7 +140,7 @@ class AddictionsProvider with ChangeNotifier { // add a code that reverts the reorder if db fails } - void createNote(Map data, String id) async { + void createNote(Map data, String? id) async { final addiction = _addictions.firstWhere((addiction) => addiction.id == id); final newNote = PersonalNote( title: data['title'], @@ -156,11 +156,11 @@ class AddictionsProvider with ChangeNotifier { 'date': data['date'], }, ); - addiction.personalNotes.add(newNote); + addiction.personalNotes!.add(newNote); notifyListeners(); } - Future fetchNotes(String id) async { + Future fetchNotes(String? id) async { final List loadedNotes = []; final addiction = _addictions.firstWhere((addiction) => addiction.id == id); final notes = await DBHelper.getData( @@ -171,16 +171,16 @@ class AddictionsProvider with ChangeNotifier { notes.forEach((note) { loadedNotes.add( PersonalNote( - title: note['title'], - text: note['text'], - date: note['date'], + title: note['title'] as String?, + text: note['text'] as String?, + date: note['date'] as String?, ), ); }); addiction.personalNotes = loadedNotes; } - void createGift(Map data, String id) async { + void createGift(Map data, String? id) async { final addiction = _addictions.firstWhere((addiction) => addiction.id == id); final giftId = Uuid().v1(); final newGift = Gift( @@ -188,7 +188,7 @@ class AddictionsProvider with ChangeNotifier { addictionId: id, name: data['name'], price: data['price'], - sortOrder: addiction.gifts.length, + sortOrder: addiction.gifts!.length, ); await DBHelper.insert( 'gifts', @@ -198,14 +198,14 @@ class AddictionsProvider with ChangeNotifier { 'name': data['name'], 'price': data['price'], 'count': 0, - 'sort_order': addiction.gifts.length, + 'sort_order': addiction.gifts!.length, }, ); - addiction.gifts.add(newGift); + addiction.gifts!.add(newGift); notifyListeners(); } - Future fetchGifts(String id) async { + Future fetchGifts(String? id) async { final List loadedGifts = []; final addiction = _addictions.firstWhere((addiction) => addiction.id == id); final gifts = await DBHelper.getData( @@ -216,16 +216,16 @@ class AddictionsProvider with ChangeNotifier { gifts.forEach((gift) { loadedGifts.add( Gift( - id: gift['id'], - addictionId: gift['addiction_id'], - name: gift['name'], - price: gift['price'], - count: gift['count'], - sortOrder: gift['sort_order'], + id: gift['id'] as String?, + addictionId: gift['addiction_id'] as String?, + name: gift['name'] as String?, + price: gift['price'] as double?, + count: gift['count'] as int?, + sortOrder: gift['sort_order'] as int?, ), ); }); - loadedGifts.sort((a, b) => a.sortOrder.compareTo(b.sortOrder)); + loadedGifts.sort((a, b) => a.sortOrder!.compareTo(b.sortOrder!)); addiction.gifts = loadedGifts; notifyListeners(); } @@ -233,21 +233,21 @@ class AddictionsProvider with ChangeNotifier { void deleteGift(Gift gift) async { final addiction = _addictions.firstWhere((addiction) => addiction.id == gift.addictionId); - addiction.gifts.remove(gift); + addiction.gifts!.remove(gift); notifyListeners(); final temp = - addiction.gifts.where((g) => g.sortOrder > addiction.sortOrder); + addiction.gifts!.where((g) => g.sortOrder! > addiction.sortOrder!); temp.forEach((g) async { - g.sortOrder--; + g.sortOrder = g.sortOrder! - 1; await DBHelper.update('gifts', 'sort_order', g.id, g.sortOrder); }); await DBHelper.delete('gifts', gift.id); } - Future reorderGifts(int oldIndex, int newIndex, String id) async { + Future reorderGifts(int oldIndex, int newIndex, String? id) async { final addiction = _addictions.firstWhere((addiction) => addiction.id == id); - final temp = addiction.gifts.removeAt(oldIndex); - addiction.gifts.insert(newIndex, temp); + final temp = addiction.gifts!.removeAt(oldIndex); + addiction.gifts!.insert(newIndex, temp); await DBHelper.reorder( 'gifts', 'sort_order', @@ -261,7 +261,7 @@ class AddictionsProvider with ChangeNotifier { } void buyGift(Gift gift) async { - gift.count = gift.count + 1; + gift.count = gift.count! + 1; await DBHelper.update( 'gifts', 'count', diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index b180661..9e55447 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -1,19 +1,21 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; class SettingsProvider with ChangeNotifier { - SharedPreferences _prefs; + SharedPreferences? _prefs; - String get currency { - return _prefs.getString('currency'); + String? get currency { + return _prefs!.getString('currency'); } - bool get receiveProgressNotifs { - return _prefs.getBool('allowProgressNotif'); + bool? get receiveProgressNotifs { + return _prefs!.getBool('allowProgressNotif'); } - bool get receiveQuoteNotifs { - return _prefs.getBool('allowQuoteNotif'); + bool? get receiveQuoteNotifs { + return _prefs!.getBool('allowQuoteNotif'); } Future _initPrefs() async { @@ -24,29 +26,30 @@ class SettingsProvider with ChangeNotifier { Future loadPrefs() async { await _initPrefs(); - _prefs.getBool('allowProgressNotif') ?? - await _prefs.setBool('allowProgressNotif', true); - _prefs.getString('allowQuoteNotif') ?? - await _prefs.setBool('allowQuoteNotif', true); - _prefs.getString('currency') ?? await _prefs.setString('currency', 'USD'); + _prefs!.getBool('allowProgressNotif') ?? + await _prefs!.setBool('allowProgressNotif', true); + _prefs!.getString('allowQuoteNotif') ?? + await (_prefs!.setBool('allowQuoteNotif', true) as FutureOr); + _prefs!.getString('currency') ?? + await (_prefs!.setString('currency', 'USD') as FutureOr); notifyListeners(); } void updateCurrency(String newCurrency) async { await _initPrefs(); - await _prefs.setString('currency', newCurrency); + await _prefs!.setString('currency', newCurrency); notifyListeners(); } void allowQuoteNotif(bool isAllowed) async { await _initPrefs(); - await _prefs.setBool('allowQuoteNotif', isAllowed); + await _prefs!.setBool('allowQuoteNotif', isAllowed); notifyListeners(); } void allowProgressNotif(bool isAllowed) async { await _initPrefs(); - await _prefs.setBool('allowProgressNotif', isAllowed); + await _prefs!.setBool('allowProgressNotif', isAllowed); notifyListeners(); } } diff --git a/lib/screens/addiction_item_screen.dart b/lib/screens/addiction_item_screen.dart index 8e689cb..666c814 100644 --- a/lib/screens/addiction_item_screen.dart +++ b/lib/screens/addiction_item_screen.dart @@ -41,7 +41,7 @@ class _AddictionItemState extends State { Widget build(BuildContext context) { final t = Theme.of(context); final AddictionItemScreenArgs args = - ModalRoute.of(context).settings.arguments; + ModalRoute.of(context)!.settings.arguments as AddictionItemScreenArgs; final local = AppLocalizations.of(context); List _buildScreens() { @@ -56,21 +56,21 @@ class _AddictionItemState extends State { return [ PersistentBottomNavBarItem( icon: FaIcon(FontAwesomeIcons.infoCircle), - title: (local.overview), - activeColor: t.primaryColor, - inactiveColor: t.hintColor, + title: (local!.overview), + activeColorPrimary: t.primaryColor, + inactiveColorPrimary: t.hintColor, ), PersistentBottomNavBarItem( icon: FaIcon(FontAwesomeIcons.gifts), title: (local.rewards), - activeColor: t.primaryColor, - inactiveColor: t.hintColor, + activeColorPrimary: t.primaryColor, + inactiveColorPrimary: t.hintColor, ), PersistentBottomNavBarItem( icon: FaIcon(FontAwesomeIcons.trophy), title: (local.achievements), - activeColor: t.primaryColor, - inactiveColor: t.hintColor, + activeColorPrimary: t.primaryColor, + inactiveColorPrimary: t.hintColor, ), ]; } @@ -84,10 +84,10 @@ class _AddictionItemState extends State { ), body: GestureDetector( onHorizontalDragEnd: (details) { - if (details.primaryVelocity < -400 && + if (details.primaryVelocity! < -400 && _controller.index < tabLength - 1) { _controller.jumpToTab(_controller.index + 1); - } else if (details.primaryVelocity > 400 && _controller.index > 0) { + } else if (details.primaryVelocity! > 400 && _controller.index > 0) { _controller.jumpToTab(_controller.index - 1); } }, diff --git a/lib/screens/addictions_screen.dart b/lib/screens/addictions_screen.dart index 8d17d52..ce96453 100644 --- a/lib/screens/addictions_screen.dart +++ b/lib/screens/addictions_screen.dart @@ -23,15 +23,15 @@ class _AddictionsScreenState extends State { _setProgNotifTasks(List addictions) async { if (Provider.of(context, listen: false) - .receiveProgressNotifs) { + .receiveProgressNotifs!) { for (var addiction in addictions) { - if (addiction.level < levelDurations.length - 1) { - Workmanager.registerPeriodicTask( + if (addiction.level! < levelDurations.length - 1) { + Workmanager().registerPeriodicTask( addiction.id, 'progress-notification', inputData: { 'id': addiction.id, - 'locale': AppLocalizations.of(context).localeName, + 'locale': AppLocalizations.of(context)!.localeName, }, frequency: Duration(minutes: 15), existingWorkPolicy: ExistingWorkPolicy.keep, @@ -44,7 +44,7 @@ class _AddictionsScreenState extends State { ), ); } else { - Workmanager.cancelByUniqueName(addiction.id); + Workmanager().cancelByUniqueName(addiction.id); } } } @@ -64,7 +64,7 @@ class _AddictionsScreenState extends State { '${removedAddiction.name} deleted.', ), action: SnackBarAction( - label: local.undo, + label: local!.undo, onPressed: () { Provider.of(context, listen: false) .insertAddiction(removedAddiction); @@ -89,7 +89,7 @@ class _AddictionsScreenState extends State { Widget build(BuildContext context) { final t = Theme.of(context); final deviceSize = MediaQuery.of(context).size; - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; void pushCreateAddictionScreen() { Navigator.of(context).push( @@ -107,7 +107,7 @@ class _AddictionsScreenState extends State { leading: IconButton( icon: Icon(Icons.menu), onPressed: () { - _scaffoldKey.currentState.openDrawer(); + _scaffoldKey.currentState!.openDrawer(); }, ), ), @@ -152,7 +152,7 @@ class _AddictionsScreenState extends State { onReorder: _onReorder, ), ) - : child; + : child!; }, child: InkWell( onTap: pushCreateAddictionScreen, @@ -172,7 +172,7 @@ class _AddictionsScreenState extends State { foregroundColor: t.canvasColor, child: Icon( Icons.add, - size: t.textTheme.headline1.fontSize, + size: t.textTheme.headline1!.fontSize, ), onPressed: null, ), @@ -185,7 +185,7 @@ class _AddictionsScreenState extends State { child: Text( local.appName, style: TextStyle( - fontSize: t.textTheme.headline2.fontSize, + fontSize: t.textTheme.headline2!.fontSize, color: t.primaryColor, fontWeight: FontWeight.bold, ), diff --git a/lib/screens/create_addiction_screen.dart b/lib/screens/create_addiction_screen.dart index e13ed3e..e754ee4 100644 --- a/lib/screens/create_addiction_screen.dart +++ b/lib/screens/create_addiction_screen.dart @@ -45,9 +45,9 @@ class AddictionCard extends StatefulWidget { class _AddictionCardState extends State with SingleTickerProviderStateMixin { final GlobalKey _formKey = GlobalKey(); - String _consumptionType; - FocusNode _focusNode; - AnimationController _dpAnimController; + String? _consumptionType; + FocusNode? _focusNode; + late AnimationController _dpAnimController; var addictionData = { 'name': '', 'quit_date': DateTime.now().toString(), @@ -60,7 +60,7 @@ class _AddictionCardState extends State void _selectDate(context, DateTime currentlyPicked) async { //pick date - DateTime date = await showDatePicker( + DateTime? date = await showDatePicker( context: context, builder: (context, child) { _dpAnimController.forward(); @@ -77,7 +77,7 @@ class _AddictionCardState extends State // check if datepicker canceled if (date != null) { - TimeOfDay time = await showTimePicker( + TimeOfDay? time = await showTimePicker( context: context, builder: (context, child) { _dpAnimController.forward(); @@ -104,7 +104,7 @@ class _AddictionCardState extends State ..showSnackBar( SnackBar( content: Text( - AppLocalizations.of(context).cantPickFutureTime, + AppLocalizations.of(context)!.cantPickFutureTime, ), ), ); @@ -132,11 +132,11 @@ class _AddictionCardState extends State } void trySubmit() async { - final isValid = _formKey.currentState.validate(); + final isValid = _formKey.currentState!.validate(); FocusScope.of(context).unfocus(); if (isValid) { - _formKey.currentState.save(); + _formKey.currentState!.save(); final newAddiction = await Provider.of(context, listen: false) .createAddiction(addictionData); @@ -177,14 +177,14 @@ class _AddictionCardState extends State @override void dispose() { _dpAnimController.dispose(); - _focusNode.dispose(); + _focusNode!.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final deviceSize = MediaQuery.of(context).size; return Container( @@ -228,7 +228,7 @@ class _AddictionCardState extends State FocusScope.of(context).unfocus(); _selectDate( context, - DateTime.parse(addictionData['quit_date']), + DateTime.parse(addictionData['quit_date'] as String), ); }); }, @@ -245,7 +245,7 @@ class _AddictionCardState extends State style: TextStyle( fontSize: Theme.of(context) .textTheme - .subtitle2 + .subtitle2! .fontSize, fontWeight: FontWeight.bold, color: t.hintColor, @@ -260,7 +260,7 @@ class _AddictionCardState extends State Text( DateFormat('dd/MM/yyyy').format( DateTime.parse( - addictionData['quit_date']), + addictionData['quit_date'] as String), ), style: TextStyle( color: t.hintColor, @@ -385,7 +385,7 @@ class _AddictionCardState extends State style: TextStyle( fontSize: Theme.of(context) .textTheme - .subtitle2 + .subtitle2! .fontSize, fontWeight: FontWeight.bold, color: t.hintColor, @@ -393,12 +393,12 @@ class _AddictionCardState extends State ), Text( _consumptionType != null - ? _consumptionType + ? _consumptionType! : local.quantity, style: TextStyle( fontSize: Theme.of(context) .textTheme - .subtitle2 + .subtitle2! .fontSize, color: t.hintColor, ), @@ -456,7 +456,7 @@ class _AddictionCardState extends State child: Text( local.quitAddiction, style: TextStyle( - fontSize: t.textTheme.headline6.fontSize, + fontSize: t.textTheme.headline6!.fontSize, ), ), ), diff --git a/lib/util/custom_localizations.dart b/lib/util/custom_localizations.dart index 10df2b4..87ccac0 100644 --- a/lib/util/custom_localizations.dart +++ b/lib/util/custom_localizations.dart @@ -1,4 +1,4 @@ -String progressNotificationMsg(int newLevel, String locale) { +String progressNotificationMsg(int newLevel, String? locale) { switch (locale) { case 'en': return 'You have reached level $newLevel!'; diff --git a/lib/util/progress_constants.dart b/lib/util/progress_constants.dart index b172a15..96962f2 100644 --- a/lib/util/progress_constants.dart +++ b/lib/util/progress_constants.dart @@ -43,7 +43,7 @@ const _levelNames = { }; List getLevelNames(String locale) { - return [..._levelNames[locale]]; + return [..._levelNames[locale]!]; } const _achievementDurations = [ diff --git a/lib/widgets/achievements.dart b/lib/widgets/achievements.dart index c96b7c6..e6e429f 100644 --- a/lib/widgets/achievements.dart +++ b/lib/widgets/achievements.dart @@ -3,15 +3,15 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:liquid_progress_indicator/liquid_progress_indicator.dart'; import 'package:confetti/confetti.dart'; +import 'package:liquid_progress_indicator_ns/liquid_progress_indicator.dart'; import 'package:quittle/extensions/duration_extension.dart'; import 'package:quittle/models/addiction.dart'; import 'package:quittle/util/progress_constants.dart'; class Achievements extends StatefulWidget { - final Addiction data; + final Addiction? data; const Achievements({ this.data, @@ -22,16 +22,16 @@ class Achievements extends StatefulWidget { } class _AchievementsState extends State { - int maxAchLevel; - List localizedAchDurations; - int achLevel; - double percentage; + int? maxAchLevel; + late List localizedAchDurations; + int? achLevel; + late double percentage; initialAnimation() { - final targetPercentage = (widget.data.abstinenceTime.inMinutes / + final num targetPercentage = (widget.data!.abstinenceTime.inMinutes / achievementDurations.last.inMinutes) .clamp(0.0, 1.0); - final targetLevel = widget.data.achievementLevel; + final targetLevel = widget.data!.achievementLevel; int nextAchLevel = 1; Timer.periodic(Duration(milliseconds: 100), (timer) { if (percentage < targetPercentage && mounted) { @@ -40,7 +40,7 @@ class _AchievementsState extends State { if ((achievementDurations[nextAchLevel].inMinutes / achievementDurations.last.inMinutes) <= percentage && - achLevel < targetLevel) { + achLevel! < targetLevel!) { achLevel = nextAchLevel; nextAchLevel++; } @@ -78,25 +78,25 @@ class _AchievementsState extends State { return pos; } - void _getLocalizedAchievementDurations(AppLocalizations local) { + void _getLocalizedAchievementDurations(AppLocalizations? local) { localizedAchDurations[0] = 'A New Start!'; for (var i = 1; i < achievementDurations.length; i++) { if (achievementDurations[i].inDays < 30) { localizedAchDurations[i] = - ('${achievementDurations[i].inDays} ${local.day(achievementDurations[i].inDays)}'); + ('${achievementDurations[i].inDays} ${local!.day(achievementDurations[i].inDays)}'); } else if (achievementDurations[i].inDays < 360) { final int inMonths = (achievementDurations[i].inDays / 30).floor(); - localizedAchDurations[i] = ('$inMonths ${local.month(inMonths)}'); + localizedAchDurations[i] = ('$inMonths ${local!.month(inMonths)}'); } else { final int inYears = (achievementDurations[i].inDays / 360).floor(); - localizedAchDurations[i] = ('$inYears ${local.year(inYears)}'); + localizedAchDurations[i] = ('$inYears ${local!.year(inYears)}'); } } } @override void didUpdateWidget(covariant Achievements oldWidget) { - percentage = (widget.data.abstinenceTime.inMinutes / + percentage = (widget.data!.abstinenceTime.inMinutes / achievementDurations.last.inMinutes) .clamp(0.0, 1.0); super.didUpdateWidget(oldWidget); @@ -110,7 +110,7 @@ class _AchievementsState extends State { final double tileHeight = deviceSize.width; double totalHeight = 0.0; List achievementHeights = []; - for (var i = 0; i < maxAchLevel; i++) { + for (var i = 0; i < maxAchLevel!; i++) { achievementHeights.add( tileHeight * (achievementDurations[i + 1] - achievementDurations[i]).in30s, @@ -143,6 +143,9 @@ class _AchievementsState extends State { ), backgroundColor: Colors.transparent, direction: Axis.vertical, + borderWidth: 0, + borderColor: Colors.transparent, + borderRadius: 0, ), ], ), @@ -184,7 +187,7 @@ class _AchievementsState extends State { ), ), ...List.generate( - maxAchLevel, + maxAchLevel!, (index) => Positioned( bottom: getVerticalPosition(tileHeight, index), child: Trophy( @@ -192,9 +195,9 @@ class _AchievementsState extends State { // subtitle: localizedAchDurations[index + 1], level: index + 1, height: achievementHeights[index], - trophySize: t.textTheme.headline3.fontSize * + trophySize: t.textTheme.headline3!.fontSize! * (index + 1).clamp(0.0, deviceSize.width * .5), - active: index + 1 <= achLevel ? true : false, + active: index + 1 <= achLevel! ? true : false, ), ), ).reversed @@ -232,7 +235,7 @@ class Trophy extends StatefulWidget { } class _TrophyState extends State { - ConfettiController _confettiController; + late ConfettiController _confettiController; bool _isPlayed = false; @override @@ -273,10 +276,10 @@ class _TrophyState extends State { ); final bool isTitleOverflowed = widget.trophySize / widget.title.length < - t.textTheme.bodyText1.fontSize; + t.textTheme.bodyText1!.fontSize!; final bool isSubtitleOverflowed = widget.trophySize / widget.subtitle.length < - t.textTheme.bodyText1.fontSize; + t.textTheme.bodyText1!.fontSize!; return ConfettiWidget( confettiController: _confettiController, @@ -300,7 +303,7 @@ class _TrophyState extends State { Padding( padding: EdgeInsets.only( top: isTitleOverflowed - ? t.textTheme.bodyText1.fontSize * + ? t.textTheme.bodyText1!.fontSize! * (isSubtitleOverflowed ? 2 : 1) : 0.0, ), @@ -325,7 +328,7 @@ class _TrophyState extends State { ), Positioned( top: isSubtitleOverflowed - ? t.textTheme.bodyText1.fontSize + ? t.textTheme.bodyText1!.fontSize : widget.trophySize * .4, child: Text( widget.subtitle, diff --git a/lib/widgets/addiction_details.dart b/lib/widgets/addiction_details.dart index da447d2..70a9239 100644 --- a/lib/widgets/addiction_details.dart +++ b/lib/widgets/addiction_details.dart @@ -9,7 +9,7 @@ import 'package:quittle/widgets/duration_counter.dart'; class AddictionDetails extends StatelessWidget { const AddictionDetails({ - @required this.addictionData, + required this.addictionData, }); final Addiction addictionData; @@ -21,7 +21,7 @@ class AddictionDetails extends StatelessWidget { final Duration abstinenceTime = addictionData.abstinenceTime; final double dailySavings = addictionData.dailyConsumption * addictionData.unitCost; - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final currency = Provider.of(context).currency; final String quitDateFormatted = DateFormat.yMMMd(local.localeName).format(addictionData.quitDateTime); @@ -34,7 +34,7 @@ class AddictionDetails extends StatelessWidget { )); return DefaultTextStyle( - style: t.textTheme.bodyText2.copyWith( + style: t.textTheme.bodyText2!.copyWith( fontWeight: FontWeight.bold, ), child: Padding( diff --git a/lib/widgets/addiction_item.dart b/lib/widgets/addiction_item.dart index 9fe3fd4..84f5128 100644 --- a/lib/widgets/addiction_item.dart +++ b/lib/widgets/addiction_item.dart @@ -7,7 +7,7 @@ import 'package:quittle/widgets/personal_notes_view.dart'; class AddictionItem extends StatelessWidget { const AddictionItem({ - @required this.args, + required this.args, }); final AddictionItemScreenArgs args; diff --git a/lib/widgets/addiction_item_card.dart b/lib/widgets/addiction_item_card.dart index 00f12c1..f7984b0 100644 --- a/lib/widgets/addiction_item_card.dart +++ b/lib/widgets/addiction_item_card.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'dart:ui' as ui; import 'dart:typed_data'; @@ -19,9 +20,9 @@ import 'package:quittle/widgets/addiction_progress.dart'; class AddictionItemCard extends StatelessWidget { AddictionItemCard({ - @required this.addictionData, - @required this.onDelete, - @required key, + required this.addictionData, + required this.onDelete, + required key, }) : super(key: key); final Addiction addictionData; @@ -36,17 +37,17 @@ class AddictionItemCard extends StatelessWidget { _share() async { RenderRepaintBoundary boundary = - _cardKey.currentContext.findRenderObject(); + _cardKey.currentContext!.findRenderObject() as RenderRepaintBoundary; ui.Image image = await boundary.toImage(pixelRatio: 2.0); - ByteData byteData = - await image.toByteData(format: ui.ImageByteFormat.png); + ByteData byteData = await (image.toByteData( + format: ui.ImageByteFormat.png) as FutureOr); Uint8List pngBytes = byteData.buffer.asUint8List(); final directory = (await getApplicationDocumentsDirectory()).path; File imgFile = File('$directory/screenshot_shared.png'); await imgFile.writeAsBytes(pngBytes); Share.shareFiles( ['$directory/screenshot_shared.png'], - text: local.shareMsg, + text: local!.shareMsg, subject: local.shareMsgSubject, ); } @@ -94,7 +95,7 @@ class AddictionItemCard extends StatelessWidget { ), actions: [ IconSlideAction( - caption: local.share, + caption: local!.share, color: t.accentColor, icon: Icons.share, onTap: _share, @@ -135,9 +136,9 @@ class AddictionItemCard extends StatelessWidget { fontWeight: FontWeight.bold, fontSize: Theme.of(context) .textTheme - .headline5 + .headline5! .fontSize, - color: t.textTheme.bodyText1.color, + color: t.textTheme.bodyText1!.color, ), ), ), diff --git a/lib/widgets/addiction_progress.dart b/lib/widgets/addiction_progress.dart index 9534d6e..dfaf36f 100644 --- a/lib/widgets/addiction_progress.dart +++ b/lib/widgets/addiction_progress.dart @@ -10,8 +10,8 @@ import 'package:quittle/widgets/target_duration_indicator.dart'; class AddictionProgress extends StatelessWidget { const AddictionProgress({ - Key key, - @required this.addictionData, + Key? key, + required this.addictionData, }) : super(key: key); final Addiction addictionData; @@ -19,7 +19,7 @@ class AddictionProgress extends StatelessWidget { @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final consumptionType = (addictionData.consumptionType == 1) ? local.hour(addictionData.notUsedCount.toInt()) : local.times(addictionData.notUsedCount.toInt()); @@ -37,8 +37,8 @@ class AddictionProgress extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ DefaultTextStyle( - style: t.textTheme.bodyText1.copyWith( - fontSize: t.textTheme.subtitle1.fontSize, + style: t.textTheme.bodyText1!.copyWith( + fontSize: t.textTheme.subtitle1!.fontSize, fontWeight: FontWeight.bold, ), child: Column( @@ -46,10 +46,10 @@ class AddictionProgress extends StatelessWidget { Text( local.level + ' ' + - (addictionData.level + 1).toString(), + (addictionData.level! + 1).toString(), ), Text( - getLevelNames(local.localeName)[addictionData.level], + getLevelNames(local.localeName)[addictionData.level!], ) ], ), @@ -59,8 +59,8 @@ class AddictionProgress extends StatelessWidget { thickness: 0, ), DefaultTextStyle( - style: t.textTheme.bodyText1.copyWith( - fontSize: t.textTheme.subtitle1.fontSize, + style: t.textTheme.bodyText1!.copyWith( + fontSize: t.textTheme.subtitle1!.fontSize, fontWeight: FontWeight.bold, ), child: FittedBox( diff --git a/lib/widgets/currency_picker.dart b/lib/widgets/currency_picker.dart index 1f418fb..f415014 100644 --- a/lib/widgets/currency_picker.dart +++ b/lib/widgets/currency_picker.dart @@ -7,7 +7,7 @@ import 'package:provider/provider.dart'; import 'package:quittle/providers/settings_provider.dart'; class CurrencyPicker extends StatefulWidget { - final Function onUpdate; + final Function? onUpdate; const CurrencyPicker({ this.onUpdate, @@ -18,7 +18,7 @@ class CurrencyPicker extends StatefulWidget { } class _CurrencyPickerState extends State { - List _currencies = []; + List? _currencies = []; Future getJson() async { final String response = @@ -50,7 +50,7 @@ class _CurrencyPickerState extends State { height: deviceHeight * .8, width: deviceWidth * .4, child: ListView.builder( - itemCount: _currencies.length, + itemCount: _currencies!.length, itemBuilder: (context, index) => TextButton( style: ButtonStyle( shape: MaterialStateProperty.all( @@ -69,12 +69,12 @@ class _CurrencyPickerState extends State { ), onPressed: () { Provider.of(context, listen: false) - .updateCurrency(_currencies[index]['code']); - widget.onUpdate(_currencies[index]['code']); - Navigator.of(context).pop(_currencies[index]['code']); + .updateCurrency(_currencies![index]['code']); + widget.onUpdate!(_currencies![index]['code']); + Navigator.of(context).pop(_currencies![index]['code']); }, child: Text( - _currencies[index]['code'], + _currencies![index]['code'], style: TextStyle( color: t.accentColor, ), diff --git a/lib/widgets/custom_text_form_field.dart b/lib/widgets/custom_text_form_field.dart index 5ac1d98..c8b1f3c 100644 --- a/lib/widgets/custom_text_form_field.dart +++ b/lib/widgets/custom_text_form_field.dart @@ -3,10 +3,10 @@ import 'package:flutter/services.dart'; class CustomTextFormField extends StatelessWidget { const CustomTextFormField( - {Key key, - @required this.valKey, - @required this.data, - @required this.inputName, + {Key? key, + required this.valKey, + required this.data, + required this.inputName, this.focusNode, this.inputType, this.validator, @@ -17,15 +17,15 @@ class CustomTextFormField extends StatelessWidget { : super(key: key); final String valKey; - final Map data; + final Map data; final String inputName; - final TextInputType inputType; - final Function validator; - final FocusNode focusNode; - final TextInputAction inputAction; - final Color backgroundColor; - final Function onSubmit; - final int maxLength; + final TextInputType? inputType; + final Function? validator; + final FocusNode? focusNode; + final TextInputAction? inputAction; + final Color? backgroundColor; + final Function? onSubmit; + final int? maxLength; @override Widget build(BuildContext context) { @@ -36,7 +36,7 @@ class CustomTextFormField extends StatelessWidget { return TextFormField( onFieldSubmitted: (_) { if (inputAction != TextInputAction.done) return; - onSubmit(); + onSubmit!(); }, focusNode: focusNode, key: ValueKey(valKey), @@ -68,7 +68,7 @@ class CustomTextFormField extends StatelessWidget { ), cursorColor: t.primaryColor, keyboardType: inputType, - validator: validator, + validator: validator as String? Function(String?)?, textInputAction: inputAction, maxLength: maxLength, maxLengthEnforcement: MaxLengthEnforcement.enforced, @@ -80,10 +80,10 @@ class CustomTextFormField extends StatelessWidget { var value; switch (data[valKey].runtimeType) { case int: - value = input is int ? input : int.parse(input); + value = input is int ? input : int.parse(input!); break; case double: - value = input is double ? input : double.parse(input); + value = input is double ? input : double.parse(input!); break; case String: value = input is String ? input : input.toString(); diff --git a/lib/widgets/duration_counter.dart b/lib/widgets/duration_counter.dart index 268244c..a1113a1 100644 --- a/lib/widgets/duration_counter.dart +++ b/lib/widgets/duration_counter.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; class DurationCounter extends StatefulWidget { const DurationCounter({ - @required this.duration, + required this.duration, }); final Duration duration; @@ -15,7 +15,7 @@ class DurationCounter extends StatefulWidget { class _DurationCounterState extends State { String durationAsString = ''; - Duration updatedDuration; + late Duration updatedDuration; String durationString(Duration duration) { String twoDigits(int n) => n.toString().padLeft(2, '0'); diff --git a/lib/widgets/gifts.dart b/lib/widgets/gifts.dart index 7f4ff70..9a058f5 100644 --- a/lib/widgets/gifts.dart +++ b/lib/widgets/gifts.dart @@ -13,7 +13,7 @@ import 'package:quittle/providers/settings_provider.dart'; import 'package:quittle/widgets/gifts_create.dart'; class Gifts extends StatefulWidget { - final Addiction data; + final Addiction? data; Gifts({ this.data, @@ -24,11 +24,11 @@ class Gifts extends StatefulWidget { } class _GiftsState extends State { - List _tiles; - String currency; + List? _tiles; + String? currency; - List _getTiles(Addiction data) { - _tiles = data.gifts + List? _getTiles(Addiction data) { + _tiles = data.gifts! .map( (gift) => GiftCard( gift: gift, @@ -47,12 +47,12 @@ class _GiftsState extends State { void _onReorder(int oldIndex, int newIndex) { setState(() { - if (_tiles.elementAt(oldIndex).runtimeType == AddGiftButton || - newIndex == _tiles.length - 1) { + if (_tiles!.elementAt(oldIndex).runtimeType == AddGiftButton || + newIndex == _tiles!.length - 1) { return; } Provider.of(context, listen: false) - .reorderGifts(oldIndex, newIndex, widget.data.id); + .reorderGifts(oldIndex, newIndex, widget.data!.id); }); } @@ -61,7 +61,7 @@ class _GiftsState extends State { Future.delayed(Duration.zero, () { setState(() { Provider.of(context, listen: false) - .fetchGifts(widget.data.id); + .fetchGifts(widget.data!.id); }); }); currency = Provider.of(context, listen: false).currency; @@ -88,59 +88,61 @@ class _GiftsState extends State { maxMainAxisCount: 2, spacing: deviceSize.width * .0399, runSpacing: deviceSize.width * .04, - children: _getTiles(widget.data), + children: _getTiles(widget.data!)!, onReorder: _onReorder, needsLongPressDraggable: true, - header: Padding( - padding: const EdgeInsets.all(16.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Row( - children: [ - Text( - local.available + ' ', - style: TextStyle( - color: t.hintColor, - fontWeight: FontWeight.bold, + header: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Row( + children: [ + Text( + local!.available + ' ', + style: TextStyle( + color: t.hintColor, + fontWeight: FontWeight.bold, + ), ), - ), - Text( - NumberFormat.simpleCurrency( - name: currency, - locale: local.localeName, - ).format(widget.data.availableMoney), - style: TextStyle( - color: Colors.green[800], - fontWeight: FontWeight.bold, + Text( + NumberFormat.simpleCurrency( + name: currency, + locale: local.localeName, + ).format(widget.data!.availableMoney), + style: TextStyle( + color: Colors.green[800], + fontWeight: FontWeight.bold, + ), ), - ), - ], - ), - Row( - children: [ - Text( - local.spent + ' ', - style: TextStyle( - color: t.hintColor, - fontWeight: FontWeight.bold, + ], + ), + Row( + children: [ + Text( + local.spent + ' ', + style: TextStyle( + color: t.hintColor, + fontWeight: FontWeight.bold, + ), ), - ), - Text( - NumberFormat.simpleCurrency( - name: currency, - locale: local.localeName, - ).format(widget.data.totalSpent), - style: TextStyle( - color: Colors.green[800], - fontWeight: FontWeight.bold, + Text( + NumberFormat.simpleCurrency( + name: currency, + locale: local.localeName, + ).format(widget.data!.totalSpent), + style: TextStyle( + color: Colors.green[800], + fontWeight: FontWeight.bold, + ), ), - ), - ], - ), - ], - ), - ), + ], + ), + ], + ), + ) + ], ), ); }), @@ -150,10 +152,10 @@ class _GiftsState extends State { class GiftCard extends StatefulWidget { const GiftCard({ - Key key, - @required this.gift, - @required this.availableMoney, - @required this.dailyGain, + Key? key, + required this.gift, + required this.availableMoney, + required this.dailyGain, }) : super(key: key); final Gift gift; @@ -165,26 +167,26 @@ class GiftCard extends StatefulWidget { } class _GiftCardState extends State { - double percentage; - String currency; + double? percentage; + String? currency; @override void initState() { - percentage = (widget.availableMoney / widget.gift.price).clamp(0.0, 1.0); + percentage = (widget.availableMoney / widget.gift.price!).clamp(0.0, 1.0); currency = Provider.of(context, listen: false).currency; super.initState(); } @override void didUpdateWidget(covariant GiftCard oldWidget) { - percentage = (widget.availableMoney / widget.gift.price).clamp(0.0, 1.0); + percentage = (widget.availableMoney / widget.gift.price!).clamp(0.0, 1.0); super.didUpdateWidget(oldWidget); } @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final materialLocal = MaterialLocalizations.of(context); final deviceSize = MediaQuery.of(context).size; final giftPrice = NumberFormat.compactSimpleCurrency( @@ -192,7 +194,7 @@ class _GiftCardState extends State { locale: local.localeName, ).format(widget.gift.price); final daysLeft = - ((widget.gift.price - widget.availableMoney) / widget.dailyGain); + ((widget.gift.price! - widget.availableMoney) / widget.dailyGain); final daysLeftClamped = daysLeft.clamp(1, 365); _deleteDialog() { @@ -248,12 +250,12 @@ class _GiftCardState extends State { context: context, builder: (context) => new AlertDialog( title: Text( - widget.availableMoney >= widget.gift.price - ? local.purchaseGiftMsg(giftPrice, widget.gift.name) + widget.availableMoney >= widget.gift.price! + ? local.purchaseGiftMsg(giftPrice, widget.gift.name!) : local.notEnoughMoney, - ), //'Purchase \"${widget.gift.name}\" for $giftPrice' + ), //'Purchase \"${widget.gift.name!}\" for $giftPrice' actions: [ - widget.availableMoney >= widget.gift.price + widget.availableMoney >= widget.gift.price! ? TextButton( onPressed: () { Navigator.of(context).pop(); @@ -262,10 +264,10 @@ class _GiftCardState extends State { materialLocal.cancelButtonLabel, ), ) - : null, + : SizedBox.shrink(), TextButton( onPressed: () { - if (widget.availableMoney >= widget.gift.price) { + if (widget.availableMoney >= widget.gift.price!) { Provider.of(context, listen: false) .buyGift(widget.gift); @@ -280,7 +282,7 @@ class _GiftCardState extends State { ), ), child: DefaultTextStyle( - style: t.textTheme.bodyText1, + style: t.textTheme.bodyText1!, child: Padding( padding: const EdgeInsets.all(16.0), child: Flex( @@ -291,7 +293,7 @@ class _GiftCardState extends State { flex: 3, fit: FlexFit.tight, child: Text( - widget.gift.name, + widget.gift.name!, style: TextStyle( fontWeight: FontWeight.bold, ), @@ -352,21 +354,21 @@ class _GiftCardState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - (percentage * 100) + (percentage! * 100) .toStringAsFixed(2) .padLeft(6) + "%", style: TextStyle( color: Theme.of(context) .textTheme - .bodyText1 + .bodyText1! .color, fontWeight: percentage == 1 ? FontWeight.w900 : null, fontSize: Theme.of(context) .textTheme - .subtitle2 + .subtitle2! .fontSize, ), ), @@ -403,7 +405,7 @@ class _GiftCardState extends State { child: Icon( Icons.delete, color: t.errorColor.withOpacity(.8), - size: t.textTheme.headline6.fontSize, + size: t.textTheme.headline6!.fontSize, ), ), onLongPress: _deleteDialog, @@ -417,9 +419,9 @@ class _GiftCardState extends State { } class AddGiftButton extends StatelessWidget { - const AddGiftButton({@required this.id}); + const AddGiftButton({required this.id}); - final String id; + final String? id; @override Widget build(BuildContext context) { @@ -453,7 +455,7 @@ class AddGiftButton extends StatelessWidget { child: Center( child: Icon( Icons.add, - size: t.textTheme.headline4.fontSize, + size: t.textTheme.headline4!.fontSize, // color: t.hintColor, ), ), diff --git a/lib/widgets/gifts_create.dart b/lib/widgets/gifts_create.dart index dff4f1e..7beb650 100644 --- a/lib/widgets/gifts_create.dart +++ b/lib/widgets/gifts_create.dart @@ -7,28 +7,28 @@ import 'package:quittle/widgets/custom_text_form_field.dart'; class CreateGift extends StatefulWidget { CreateGift({ - @required this.addictionId, + required this.addictionId, }); - final String addictionId; + final String? addictionId; @override _CreateGiftNoteState createState() => _CreateGiftNoteState(); } class _CreateGiftNoteState extends State { final GlobalKey _formKey = GlobalKey(); - FocusNode formFocusNode; + late FocusNode formFocusNode; var giftData = { 'name': '', 'price': 0.0, }; void trySubmit(BuildContext ctx) { - final isValid = _formKey.currentState.validate(); + final isValid = _formKey.currentState!.validate(); FocusScope.of(context).unfocus(); if (isValid) { - _formKey.currentState.save(); + _formKey.currentState!.save(); Provider.of(context, listen: false).createGift( giftData, widget.addictionId, @@ -53,7 +53,7 @@ class _CreateGiftNoteState extends State { @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final inputBackgroundColor = t.canvasColor; final buttonHeight = t.buttonTheme.height * 2; diff --git a/lib/widgets/note.dart b/lib/widgets/note.dart index e3ac803..0ec28bc 100644 --- a/lib/widgets/note.dart +++ b/lib/widgets/note.dart @@ -8,16 +8,16 @@ class Note extends StatelessWidget { final PersonalNote data; Note({ - @required this.data, + required this.data, }); @override Widget build(BuildContext context) { final t = Theme.of(context); final _controller = TextEditingController(text: data.text); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final quitDateFormatted = - DateFormat.yMMMd(local.localeName).format(DateTime.parse(data.date)); + DateFormat.yMMMd(local.localeName).format(DateTime.parse(data.date!)); return Container( decoration: BoxDecoration( color: t.canvasColor, @@ -41,7 +41,7 @@ class Note extends StatelessWidget { flex: 2, fit: FlexFit.tight, child: Text( - data.title, + data.title!, style: TextStyle( color: t.hintColor, fontWeight: FontWeight.bold, diff --git a/lib/widgets/personal_note_create.dart b/lib/widgets/personal_note_create.dart index 249f308..37d9b3f 100644 --- a/lib/widgets/personal_note_create.dart +++ b/lib/widgets/personal_note_create.dart @@ -9,17 +9,17 @@ import 'package:quittle/widgets/custom_text_form_field.dart'; class CreatePersonalNote extends StatefulWidget { CreatePersonalNote({ - @required this.addictionId, + required this.addictionId, }); - final String addictionId; + final String? addictionId; @override _CreatePersonalNoteState createState() => _CreatePersonalNoteState(); } class _CreatePersonalNoteState extends State { final GlobalKey _formKey = GlobalKey(); - FocusNode formFocusNode; + late FocusNode formFocusNode; var noteData = { 'title': '', 'text': '', @@ -45,11 +45,11 @@ class _CreatePersonalNoteState extends State { } void trySubmit(BuildContext ctx) { - final isValid = _formKey.currentState.validate(); + final isValid = _formKey.currentState!.validate(); FocusScope.of(context).unfocus(); if (isValid) { - _formKey.currentState.save(); + _formKey.currentState!.save(); Provider.of(context, listen: false).createNote( noteData, widget.addictionId, @@ -74,7 +74,7 @@ class _CreatePersonalNoteState extends State { @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; final deviceWidth = MediaQuery.of(context).size.width; final inputBackgroundColor = t.canvasColor; final buttonHeight = t.buttonTheme.height * 2; @@ -142,7 +142,7 @@ class _CreatePersonalNoteState extends State { maxLines: null, maxLength: 100, maxLengthEnforcement: MaxLengthEnforcement.enforced, - onSaved: (newValue) => noteData['text'] = newValue.trim(), + onSaved: (newValue) => noteData['text'] = newValue!.trim(), ), SizedBox( height: buttonHeight, @@ -171,7 +171,7 @@ class _CreatePersonalNoteState extends State { children: [ Text( DateFormat('dd/MM/yyyy').format( - DateTime.parse(noteData['date']), + DateTime.parse(noteData['date']!), ), style: TextStyle( color: t.hintColor, @@ -202,7 +202,7 @@ class _CreatePersonalNoteState extends State { }, child: Padding( padding: EdgeInsets.symmetric( - horizontal: t.textTheme.headline6.fontSize, + horizontal: t.textTheme.headline6!.fontSize!, ), child: Row( children: [ diff --git a/lib/widgets/personal_notes_view.dart b/lib/widgets/personal_notes_view.dart index 7308f6d..b944d00 100644 --- a/lib/widgets/personal_notes_view.dart +++ b/lib/widgets/personal_notes_view.dart @@ -10,7 +10,7 @@ import 'package:quittle/widgets/note.dart'; class PersonalNotesView extends StatefulWidget { PersonalNotesView({ - @required this.addictionData, + required this.addictionData, }); final Addiction addictionData; @override @@ -21,7 +21,7 @@ class _PersonalNotesViewState extends State { @override Widget build(BuildContext context) { final t = Theme.of(context); - final local = AppLocalizations.of(context); + final local = AppLocalizations.of(context)!; return Stack( alignment: Alignment.topCenter, children: [ @@ -39,7 +39,7 @@ class _PersonalNotesViewState extends State { ) : Consumer( builder: (_, addictionsData, _child) => - widget.addictionData.personalNotes.length == 0 + widget.addictionData.personalNotes!.length == 0 ? Note( data: PersonalNote( title: local.yourJourneyBegins, @@ -51,7 +51,7 @@ class _PersonalNotesViewState extends State { shrinkWrap: true, physics: BouncingScrollPhysics(), itemCount: - widget.addictionData.personalNotes.length, + widget.addictionData.personalNotes!.length, itemBuilder: (_, index) { return Padding( padding: const EdgeInsets.only(top: 8.0), diff --git a/lib/widgets/settings_view.dart b/lib/widgets/settings_view.dart index e6673b5..e8d706c 100644 --- a/lib/widgets/settings_view.dart +++ b/lib/widgets/settings_view.dart @@ -14,10 +14,10 @@ class SettingsView extends StatefulWidget { } class _SettingsViewState extends State { - bool _progressCheck = false; - bool _quoteCheck = false; - SettingsProvider settings; - String currency; + bool? _progressCheck = false; + bool? _quoteCheck = false; + late SettingsProvider settings; + String? currency; @override void initState() { @@ -68,11 +68,11 @@ class _SettingsViewState extends State { ), ), child: Text( - local.settings, + local!.settings, style: TextStyle( fontSize: Theme.of(context) .textTheme - .headline6 + .headline6! .fontSize, fontWeight: FontWeight.bold, color: t.primaryColor, @@ -92,7 +92,7 @@ class _SettingsViewState extends State { color: t.hintColor, ), ), - value: _progressCheck, + value: _progressCheck!, activeColor: t.accentColor, onChanged: (value) { if (mounted) { @@ -119,7 +119,7 @@ class _SettingsViewState extends State { color: t.hintColor, ), ), - value: _quoteCheck, + value: _quoteCheck!, activeColor: t.accentColor, onChanged: (value) { if (mounted) { @@ -149,7 +149,7 @@ class _SettingsViewState extends State { style: TextStyle( fontSize: Theme.of(context) .textTheme - .subtitle2 + .subtitle2! .fontSize, color: t.hintColor, ), @@ -164,7 +164,7 @@ class _SettingsViewState extends State { fontWeight: FontWeight.bold, fontSize: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .fontSize, ), ), @@ -212,7 +212,7 @@ class _SettingsViewState extends State { 'assets/images/font_awesome_chain.png', ), ), - applicationVersion: '1.0.0', + applicationVersion: '1.0.1', children: [ Column( crossAxisAlignment: diff --git a/lib/widgets/target_duration_indicator.dart b/lib/widgets/target_duration_indicator.dart index c66e869..943e689 100644 --- a/lib/widgets/target_duration_indicator.dart +++ b/lib/widgets/target_duration_indicator.dart @@ -6,8 +6,8 @@ import 'package:quittle/models/addiction.dart'; class TargetDurationIndicator extends StatelessWidget { TargetDurationIndicator({ - @required this.data, - @required this.local, + required this.data, + required this.local, }); final Addiction data; @@ -71,14 +71,14 @@ class TargetDurationIndicator extends StatelessWidget { ), mainLabelStyle: TextStyle( color: t.primaryColor, - fontSize: t.textTheme.headline5.fontSize, + fontSize: t.textTheme.headline5!.fontSize, fontWeight: FontWeight.bold, ), ), customWidths: CustomSliderWidths( handlerSize: 0, - progressBarWidth: t.textTheme.bodyText1.fontSize, - trackWidth: t.textTheme.bodyText1.fontSize, + progressBarWidth: t.textTheme.bodyText1!.fontSize, + trackWidth: t.textTheme.bodyText1!.fontSize, ), customColors: CustomSliderColors( hideShadow: true, diff --git a/pubspec.lock b/pubspec.lock index eb6f5cb..b14d413 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,14 +14,14 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.13" + version: "3.1.2" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.6.0" + version: "2.0.0" async: dependency: transitive description: @@ -70,21 +70,14 @@ packages: name: confetti url: "https://pub.dartlang.org" source: hosted - version: "0.5.5" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" + version: "0.6.0-nullsafety" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "3.0.1" cupertino_icons: dependency: "direct main" description: @@ -124,21 +117,21 @@ packages: name: flutter_launcher_icons url: "https://pub.dartlang.org" source: hosted - version: "0.8.1" + version: "0.9.0" flutter_local_notifications: dependency: "direct main" description: name: flutter_local_notifications url: "https://pub.dartlang.org" source: hosted - version: "4.0.1+1" + version: "5.0.0+1" flutter_local_notifications_platform_interface: dependency: transitive description: name: flutter_local_notifications_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0+1" + version: "3.0.0" flutter_localizations: dependency: "direct main" description: flutter @@ -150,14 +143,14 @@ packages: name: flutter_native_timezone url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.10" flutter_slidable: dependency: "direct main" description: name: flutter_slidable url: "https://pub.dartlang.org" source: hosted - version: "0.5.7" + version: "0.6.0" flutter_test: dependency: "direct dev" description: flutter @@ -174,14 +167,14 @@ packages: name: font_awesome_flutter url: "https://pub.dartlang.org" source: hosted - version: "8.11.0" + version: "9.0.0" image: dependency: transitive description: name: image url: "https://pub.dartlang.org" source: hosted - version: "2.1.19" + version: "3.0.2" intl: dependency: "direct main" description: @@ -196,13 +189,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" - liquid_progress_indicator: + liquid_progress_indicator_ns: dependency: "direct main" description: - name: liquid_progress_indicator + name: liquid_progress_indicator_ns url: "https://pub.dartlang.org" source: hosted - version: "0.3.2" + version: "1.0.0" matcher: dependency: transitive description: @@ -230,7 +223,7 @@ packages: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" path: dependency: "direct main" description: @@ -265,28 +258,28 @@ packages: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" persistent_bottom_nav_bar: dependency: "direct main" description: name: persistent_bottom_nav_bar url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "4.0.2" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "4.1.0" platform: dependency: transitive description: @@ -300,56 +293,56 @@ packages: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.2.1" provider: dependency: "direct main" description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.3.2+2" + version: "5.0.0" random_color: dependency: transitive description: name: random_color url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.0.6-nullsafety" reorderables: dependency: "direct main" description: name: reorderables url: "https://pub.dartlang.org" source: hosted - version: "0.3.2" + version: "0.4.1" rxdart: dependency: "direct main" description: name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "0.25.0" + version: "0.26.0" share: dependency: "direct main" description: name: share url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" shared_preferences_linux: dependency: transitive description: @@ -396,7 +389,7 @@ packages: name: sleek_circular_slider url: "https://pub.dartlang.org" source: hosted - version: "1.2.0+web" + version: "2.0.0" source_span: dependency: transitive description: @@ -410,14 +403,14 @@ packages: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.3.1+1" + version: "2.0.0+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "1.0.2+1" + version: "2.0.0+2" stack_trace: dependency: transitive description: @@ -445,7 +438,7 @@ packages: name: synchronized url: "https://pub.dartlang.org" source: hosted - version: "2.2.0+2" + version: "3.0.0" term_glyph: dependency: transitive description: @@ -466,7 +459,7 @@ packages: name: timezone url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.7.0" typed_data: dependency: transitive description: @@ -480,7 +473,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.2" + version: "6.0.3" url_launcher_linux: dependency: transitive description: @@ -501,7 +494,7 @@ packages: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" url_launcher_web: dependency: transitive description: @@ -522,7 +515,7 @@ packages: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "2.2.2" + version: "3.0.4" vector_math: dependency: transitive description: @@ -536,14 +529,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.5" workmanager: dependency: "direct main" description: name: workmanager url: "https://pub.dartlang.org" source: hosted - version: "0.2.3" + version: "0.4.0" xdg_directories: dependency: transitive description: @@ -557,14 +550,14 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "4.5.1" + version: "5.1.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.1.0" sdks: - dart: ">=2.12.0-259.9.beta <3.0.0" - flutter: ">=1.22.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index fa8d048..90c1e01 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,37 +15,36 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 1.0.1+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter - sqflite: ^1.3.1+1 - path: ^1.7.0 + sqflite: ^2.0.0+3 + path: ^1.8.0 intl: ^0.17.0 - uuid: ^2.2.2 - provider: ^4.3.2+2 - persistent_bottom_nav_bar: ^3.1.0 - reorderables: ^0.3.2 - sleek_circular_slider: ^1.2.0+web - flutter_local_notifications: ^4.0.1+1 - rxdart: ^0.25.0 - flutter_native_timezone: ^1.0.4 - workmanager: ^0.2.3 - url_launcher: ^6.0.2 - font_awesome_flutter: ^8.11.0 + uuid: ^3.0.4 + provider: ^5.0.0 + persistent_bottom_nav_bar: ^4.0.2 + reorderables: ^0.4.1 + sleek_circular_slider: ^2.0.0 + flutter_local_notifications: ^5.0.0+1 + rxdart: ^0.26.0 + flutter_native_timezone: ^1.0.10 + workmanager: ^0.4.0 + url_launcher: ^6.0.3 + font_awesome_flutter: ^9.0.0 animations: ^2.0.0 - liquid_progress_indicator: ^0.3.2 - confetti: ^0.5.5 - flutter_slidable: ^0.5.7 - share: ^2.0.0 + confetti: ^0.6.0-nullsafety + flutter_slidable: ^0.6.0 + share: ^2.0.1 path_provider: ^2.0.1 - shared_preferences: ^2.0.3 + shared_preferences: ^2.0.5 @@ -53,11 +52,12 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + liquid_progress_indicator_ns: ^1.0.0 dev_dependencies: flutter_test: sdk: flutter - flutter_launcher_icons: "^0.8.0" + flutter_launcher_icons: ^0.9.0 flutter_icons: android: "font_awesome_chain"