Skip to content

Commit

Permalink
Merge pull request #1 from iamngoni/null_safety
Browse files Browse the repository at this point in the history
feat!: null_safety
  • Loading branch information
DonnC committed Jul 9, 2021
2 parents 3c2175b + cbb1f39 commit 58b3ed0
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 165 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.0] - Dec 2020.

* Initial release.

## [2.0.0-dev] - Jul 2021.

* Null safety support.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
flutter:
sdk: flutter

bulksmszw: ^1.0.0
bulksmszw: ^2.0.0-dev
```

## How to use
Expand Down
48 changes: 24 additions & 24 deletions example/app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:bulksmszw/bulksmszw.dart';
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
Expand All @@ -21,9 +21,9 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, this.title}) : super(key: key);

final String title;
final String? title;

@override
_MyHomePageState createState() => _MyHomePageState();
Expand All @@ -32,9 +32,9 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
TextEditingController _message;
TextEditingController _recipient_1;
TextEditingController _recipient_2;
TextEditingController? _message;
TextEditingController? _recipient_1;
TextEditingController? _recipient_2;

@override
void initState() {
Expand All @@ -46,9 +46,9 @@ class _MyHomePageState extends State<MyHomePage> {

@override
void dispose() {
_message.dispose();
_recipient_1.dispose();
_recipient_2.dispose();
_message!.dispose();
_recipient_1!.dispose();
_recipient_2!.dispose();
super.dispose();
}

Expand All @@ -70,10 +70,10 @@ class _MyHomePageState extends State<MyHomePage> {
}

Widget _customTextField({
TextEditingController controller,
String validateError,
String labelText,
String hintText,
TextEditingController? controller,
String? validateError,
String? labelText,
String? hintText,
TextInputType keyboardType: TextInputType.text,
int maxLines: 1,
}) {
Expand All @@ -83,7 +83,7 @@ class _MyHomePageState extends State<MyHomePage> {
maxLines: maxLines,
controller: controller,
validator: (value) {
if (value.isEmpty) {
if (value!.isEmpty) {
return validateError;
}
return null;
Expand All @@ -110,8 +110,8 @@ class _MyHomePageState extends State<MyHomePage> {
Future<void> _sendMessage() async {
// create a list of string of recipients | contacts
List<String> _recipients = [
_recipient_1.text.trim(),
_recipient_2.text.trim(),
_recipient_1!.text.trim(),
_recipient_2!.text.trim(),
];

final api = BulkSmsZw(
Expand All @@ -122,7 +122,7 @@ class _MyHomePageState extends State<MyHomePage> {
showLoader();

ApiResponse _response = await api.send(
message: _message.text.trim(),
message: _message!.text.trim(),
recipients: _recipients,
);

Expand All @@ -131,7 +131,7 @@ class _MyHomePageState extends State<MyHomePage> {

// check api statusresponse
if (_response.statusresponse == SMSRESPONSE.SUCCESS) {
_scaffoldKey.currentState.showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.greenAccent,
content: new Text(
Expand All @@ -141,7 +141,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
} else {
_scaffoldKey.currentState.showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.red,
content: new Text(
Expand All @@ -153,9 +153,9 @@ class _MyHomePageState extends State<MyHomePage> {
}

setState(() {
_message.clear();
_recipient_1.clear();
_recipient_2.clear();
_message!.clear();
_recipient_1!.clear();
_recipient_2!.clear();
});
}

Expand All @@ -164,7 +164,7 @@ class _MyHomePageState extends State<MyHomePage> {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text(widget.title),
title: Text(widget.title!),
),
body: SingleChildScrollView(
child: Form(
Expand Down Expand Up @@ -199,7 +199,7 @@ class _MyHomePageState extends State<MyHomePage> {
padding: const EdgeInsets.all(8),
child: MaterialButton(
onPressed: () async {
if (_formKey.currentState.validate()) {
if (_formKey.currentState!.validate()) {
await _sendMessage();
}
},
Expand Down
19 changes: 9 additions & 10 deletions lib/src/bulksmszw.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:flutter/foundation.dart';

import 'models/index.dart';
import 'services/api.dart';

/// connect to bulksms zw gateway and send a text message
/// obtain authentication details from http:https://portal.bulksmsweb.com
class BulkSmsZw {
// ignore: non_constant_identifier_names
static String _BULKSMS_WEBSERVICE_URL = 'http:https://portal.bulksmsweb.com/index.php?app=ws';
static String _BULKSMS_WEBSERVICE_URL =
'http:https://portal.bulksmsweb.com/index.php?app=ws';

// ignore: non_constant_identifier_names
static String _SEND_SMS_OPERATION = 'pv';
Expand All @@ -21,12 +20,12 @@ class BulkSmsZw {
/// bulksmsweb api username
final String bulksmsWebName;

String _key;
String _name;
String? _key;
String? _name;

BulkSmsZw({
@required this.bulksmsWebKey,
@required this.bulksmsWebName,
required this.bulksmsWebKey,
required this.bulksmsWebName,
}) {
_key = bulksmsWebKey.trim();
_name = bulksmsWebName.trim();
Expand All @@ -47,8 +46,8 @@ class BulkSmsZw {
/// var resp = await api.send(message="Please be reminded, project deadline is next week!", recipients=['#developer', '2637xxxxxxx'], credits=true);
/// ```
Future<ApiResponse> send({
@required String message,
@required List<String> recipients,
required String message,
required List<String> recipients,
bool credits: false,
var schedule,
}) async {
Expand All @@ -64,7 +63,7 @@ class BulkSmsZw {
message: message + '\n',
).sendRequest();

return resp;
return resp!;
}

// ignore: non_constant_identifier_names
Expand Down
43 changes: 21 additions & 22 deletions lib/src/models/api_credits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dart:convert';

/// bulksmsweb credit response model
class ApiCredits {
final String status;
final String error;
final String? status;
final String? error;
// ignore: non_constant_identifier_names
final dynamic error_string;
final dynamic timestamp;
Expand All @@ -19,12 +19,12 @@ class ApiCredits {
});

ApiCredits copyWith({
String status,
String error,
String? status,
String? error,
// ignore: non_constant_identifier_names
String error_string,
int timestamp,
int credit,
String? error_string,
int? timestamp,
int? credit,
}) {
return ApiCredits(
status: status ?? this.status,
Expand All @@ -45,11 +45,9 @@ class ApiCredits {
};
}

factory ApiCredits.fromMap(Map<String, dynamic> map) {
if (map == null) return null;

factory ApiCredits.fromMap(Map<String, dynamic>? map) {
return ApiCredits(
status: map['status'],
status: map!['status'],
error: map['error'],
error_string: map['error_string'],
timestamp: map['timestamp'],
Expand All @@ -59,7 +57,8 @@ class ApiCredits {

String toJson() => json.encode(toMap());

factory ApiCredits.fromJson(String source) => ApiCredits.fromMap(json.decode(source));
factory ApiCredits.fromJson(String source) =>
ApiCredits.fromMap(json.decode(source));

@override
String toString() {
Expand All @@ -69,21 +68,21 @@ class ApiCredits {
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;

return o is ApiCredits &&
o.status == status &&
o.error == error &&
o.error_string == error_string &&
o.timestamp == timestamp &&
o.credit == credit;
o.status == status &&
o.error == error &&
o.error_string == error_string &&
o.timestamp == timestamp &&
o.credit == credit;
}

@override
int get hashCode {
return status.hashCode ^
error.hashCode ^
error_string.hashCode ^
timestamp.hashCode ^
credit.hashCode;
error.hashCode ^
error_string.hashCode ^
timestamp.hashCode ^
credit.hashCode;
}
}
39 changes: 19 additions & 20 deletions lib/src/models/api_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'dart:convert';

/// bulksmsweb custom onSend message error model
class ApiError {
final String status;
final String error;
final String? status;
final String? error;
// ignore: non_constant_identifier_names
final dynamic error_string;
final int timestamp;
final int? timestamp;

ApiError({
this.status,
Expand All @@ -17,11 +17,11 @@ class ApiError {
});

ApiError copyWith({
String status,
String error,
String? status,
String? error,
// ignore: non_constant_identifier_names
String error_string,
int timestamp,
String? error_string,
int? timestamp,
}) {
return ApiError(
status: status ?? this.status,
Expand All @@ -40,11 +40,9 @@ class ApiError {
};
}

factory ApiError.fromMap(Map<String, dynamic> map) {
if (map == null) return null;

factory ApiError.fromMap(Map<String, dynamic>? map) {
return ApiError(
status: map['status'],
status: map!['status'],
error: map['error'],
error_string: map['error_string'],
timestamp: map['timestamp'],
Expand All @@ -53,7 +51,8 @@ class ApiError {

String toJson() => json.encode(toMap());

factory ApiError.fromJson(String source) => ApiError.fromMap(json.decode(source));
factory ApiError.fromJson(String source) =>
ApiError.fromMap(json.decode(source));

@override
String toString() {
Expand All @@ -63,19 +62,19 @@ class ApiError {
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;

return o is ApiError &&
o.status == status &&
o.error == error &&
o.error_string == error_string &&
o.timestamp == timestamp;
o.status == status &&
o.error == error &&
o.error_string == error_string &&
o.timestamp == timestamp;
}

@override
int get hashCode {
return status.hashCode ^
error.hashCode ^
error_string.hashCode ^
timestamp.hashCode;
error.hashCode ^
error_string.hashCode ^
timestamp.hashCode;
}
}
4 changes: 2 additions & 2 deletions lib/src/models/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '../utils.dart';
/// custom api response model, preferred way to check api response
class ApiResponse {
/// returns api status code response
final SMSRESPONSE statusresponse;
final SMSRESPONSE? statusresponse;

/// returns response based on caught error or on successful
///
Expand All @@ -13,7 +13,7 @@ class ApiResponse {
final dynamic apiResponse;

/// return api response message information
final String message;
final String? message;

ApiResponse({
this.statusresponse,
Expand Down
Loading

0 comments on commit 58b3ed0

Please sign in to comment.