Skip to content

Commit 07d9d43

Browse files
Merge pull request #1 from abineshPalanisamy/master
How to change the row text style when selecting a row in Flutter DataTable (SfDataGrid)
2 parents 3871aff + 8506806 commit 07d9d43

File tree

125 files changed

+4882
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+4882
-2
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.packages
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
35+
# Symbolication related
36+
app.*.symbols
37+
38+
# Obfuscation related
39+
app.*.map.json
40+
41+
# Android Studio will place build artifacts here
42+
/android/app/debug
43+
/android/app/profile
44+
/android/app/release

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
1-
# how-to-change-the-row-text-style-when-selecting-a-row-in-Flutter-DataTable
2-
How to change the row text style when selecting a row in Flutter DataTable (SfDataGrid)?
1+
# How to change the row text style when selecting a row in Flutter DataTable (SfDataGrid)
2+
3+
We have previously covered the support to changing the color of a selected row in [Flutter DataGrid](https://www.syncfusion.com/flutter-widgets/flutter-datagrid). In this article, we will now focus on modifying the text style of a row when it is selected.
4+
5+
## STEP 1:
6+
The [DataGridRowAdapter](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/DataGridRowAdapter-class.html).buildRow() method is called whenever a row is selected. The data of the selected rows is stored in the dataGridController.selectedRows property. To modify the text color of the selected row, we need to check if the currently selected row exists in the dataGridController.selectedRows collection. If a match is found, we update the color accordingly. However, if the selected row is different from the current row, the color is set to null.
7+
8+
```dart
9+
class EmployeeDataSource extends DataGridSource {
10+
@override
11+
DataGridRowAdapter? buildRow(DataGridRow row) {
12+
Color selectedRowTextColor = Colors.amber;
13+
14+
return DataGridRowAdapter(
15+
cells: row.getCells().map<Widget>((dataGridCell) {
16+
return Container(
17+
alignment: Alignment.center,
18+
child: Text(
19+
dataGridCell.value.toString(),
20+
style: TextStyle(
21+
color: dataGridController.selectedRows.contains(row)
22+
? selectedRowTextColor
23+
: null),
24+
));
25+
}).toList());
26+
}
27+
}
28+
29+
```
30+
## STEP 2:
31+
Initialize the [SfDataGrid](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid-class.html) widget with all the required properties. To utilize the [DataGridController](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/DataGridController-class.html), we need to assign it to the [SfDataGrid.controller](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/controller.html) property.
32+
33+
```dart
34+
import 'package:flutter/material.dart';
35+
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
36+
import 'package:syncfusion_flutter_core/theme.dart';
37+
38+
DataGridController dataGridController = DataGridController();
39+
40+
class SfDataGridDemoState extends State<SfDataGridDemo> {
41+
late EmployeeDataSource _employeeDataSource;
42+
List<Employee> _employees = <Employee>[];
43+
44+
@override
45+
void initState() {
46+
super.initState();
47+
_employees = getEmployeeData();
48+
_employeeDataSource = EmployeeDataSource(_employees);
49+
}
50+
51+
@override
52+
Widget build(BuildContext context) {
53+
return Scaffold(
54+
appBar: AppBar(title: const Text('Flutter SfDataGrid')),
55+
body: SfDataGridTheme(
56+
data: SfDataGridThemeData(selectionColor: Colors.purple),
57+
child: SfDataGrid(
58+
controller: dataGridController,
59+
source: _employeeDataSource,
60+
selectionMode: SelectionMode.multiple,
61+
columns: getColumns,
62+
columnWidthMode: ColumnWidthMode.fill),
63+
),
64+
);
65+
}
66+
}
67+
68+
```

android/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks

android/app/build.gradle

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
namespace "com.example.flutter_application"
30+
compileSdkVersion flutter.compileSdkVersion
31+
ndkVersion flutter.ndkVersion
32+
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
41+
42+
sourceSets {
43+
main.java.srcDirs += 'src/main/kotlin'
44+
}
45+
46+
defaultConfig {
47+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
48+
applicationId "com.example.flutter_application"
49+
// You can update the following values to match your application needs.
50+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
51+
minSdkVersion flutter.minSdkVersion
52+
targetSdkVersion flutter.targetSdkVersion
53+
versionCode flutterVersionCode.toInteger()
54+
versionName flutterVersionName
55+
}
56+
57+
buildTypes {
58+
release {
59+
// TODO: Add your own signing config for the release build.
60+
// Signing with the debug keys for now, so `flutter run --release` works.
61+
signingConfig signingConfigs.debug
62+
}
63+
}
64+
}
65+
66+
flutter {
67+
source '../..'
68+
}
69+
70+
dependencies {
71+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
72+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application
3+
android:label="flutter_application"
4+
android:name="${applicationName}"
5+
android:icon="@mipmap/ic_launcher">
6+
<activity
7+
android:name=".MainActivity"
8+
android:exported="true"
9+
android:launchMode="singleTop"
10+
android:theme="@style/LaunchTheme"
11+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
12+
android:hardwareAccelerated="true"
13+
android:windowSoftInputMode="adjustResize">
14+
<!-- Specifies an Android theme to apply to this Activity as soon as
15+
the Android process has started. This theme is visible to the user
16+
while the Flutter UI initializes. After that, this theme continues
17+
to determine the Window background behind the Flutter UI. -->
18+
<meta-data
19+
android:name="io.flutter.embedding.android.NormalTheme"
20+
android:resource="@style/NormalTheme"
21+
/>
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN"/>
24+
<category android:name="android.intent.category.LAUNCHER"/>
25+
</intent-filter>
26+
</activity>
27+
<!-- Don't delete the meta-data below.
28+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
29+
<meta-data
30+
android:name="flutterEmbedding"
31+
android:value="2" />
32+
</application>
33+
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.example.flutter_application
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity: FlutterActivity() {
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
544 Bytes
Loading

0 commit comments

Comments
 (0)