A platform, 'Traffic-Violation-Report-System', enabling users in Taiwan to upload and share responses from law enforcement to traffic violations. This system aims for greater transparency in traffic law enforcement. It utilises Django for backend and Flutter for a separated frontend web development.
GNU Affero General Public License v3.0
0
stars
0
forks
source link
[Sweep Rules] Refactor large function in home_map.dart #117
This PR refactors the large _onMarkerTapped function in the home_map.dart file to improve code readability and maintainability. The function has been broken down into smaller, more modular functions. Additionally, the build method has been refactored into smaller, more focused methods.
Summary of Changes
Created a new function _updateViolationDetails in the _HomeMapPageState class to handle updating violation details when a marker is tapped.
Extracted code from lines 54-61 in the _onMarkerTapped function and moved it to the new _updateViolationDetails function.
Removed the extracted code from lines 54-61 in the _onMarkerTapped function and updated the function signature.
Updated the function call in line 54 to _updateViolationDetails(trafficViolationId).
Updated the function call in line 59 to _markersManagement.updateMarkerColor(_selectedViolation.id, Colors.yellow).
Created a new function _searchData in the _HomeMapPageState class to handle searching data based on keyword and date range.
Extracted code from lines 24-72 in the _HomeMapPageState class and moved it to the new _searchData function.
Removed the extracted code from lines 24-72 in the _HomeMapPageState class.
Updated the function call in line 68 to _searchData().
Created a new function _buildMap in the _HomeMapPageState class to handle building the map.
Extracted code from lines 13-73 in the _HomeMapPageState class and moved it to the new _buildMap function.
Removed the extracted code from lines 13-73 in the _HomeMapPageState class.
Updated the build method to call _buildMap instead of having the code directly in the build method.
These changes improve code modularity and make the code easier to understand and maintain.
PR Feedback (click)
I created this PR to address this rule:
"Refactor large functions to be more modular."
Description
This PR refactors the large
_onMarkerTapped
function in thehome_map.dart
file to improve code readability and maintainability. The function has been broken down into smaller, more modular functions. Additionally, thebuild
method has been refactored into smaller, more focused methods.Summary of Changes
Created a new function
_updateViolationDetails
in the_HomeMapPageState
class to handle updating violation details when a marker is tapped.Extracted code from lines 54-61 in the
_onMarkerTapped
function and moved it to the new_updateViolationDetails
function.Removed the extracted code from lines 54-61 in the
_onMarkerTapped
function and updated the function signature.Updated the function call in line 54 to
_updateViolationDetails(trafficViolationId)
.Updated the function call in line 59 to
_markersManagement.updateMarkerColor(_selectedViolation.id, Colors.yellow)
.Created a new function
_searchData
in the_HomeMapPageState
class to handle searching data based on keyword and date range.Extracted code from lines 24-72 in the
_HomeMapPageState
class and moved it to the new_searchData
function.Removed the extracted code from lines 24-72 in the
_HomeMapPageState
class.Updated the function call in line 68 to
_searchData()
.Created a new function
_buildMap
in the_HomeMapPageState
class to handle building the map.Extracted code from lines 13-73 in the
_HomeMapPageState
class and moved it to the new_buildMap
function.Removed the extracted code from lines 13-73 in the
_HomeMapPageState
class.Updated the
build
method to call_buildMap
instead of having the code directly in thebuild
method.These changes improve code modularity and make the code easier to understand and maintain.