<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Muhammad Manan</title>
    <description>The latest articles on Forem by Muhammad Manan (@loopstack33).</description>
    <link>https://forem.com/loopstack33</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F932484%2Fc9aa0ab8-b798-42ae-a82f-f05f906e217b.jpeg</url>
      <title>Forem: Muhammad Manan</title>
      <link>https://forem.com/loopstack33</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/loopstack33"/>
    <language>en</language>
    <item>
      <title>Syncfusion Data Grid Flutter</title>
      <dc:creator>Muhammad Manan</dc:creator>
      <pubDate>Fri, 27 Jan 2023 12:32:43 +0000</pubDate>
      <link>https://forem.com/loopstack33/syncfusion-data-grid-flutter-8mh</link>
      <guid>https://forem.com/loopstack33/syncfusion-data-grid-flutter-8mh</guid>
      <description>&lt;p&gt;First things first before doing anything.&lt;br&gt;
&lt;strong&gt;Add dependency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add the Syncfusion Flutter DataGrid dependency to your pubspec.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
    syncfusion_flutter_datagrid: ^latest_version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get packages&lt;/p&gt;

&lt;p&gt;Run the following command to get the required packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ flutter pub get
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Import package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Import the following package in your Dart code.&lt;/p&gt;

&lt;p&gt;DART&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:syncfusion_flutter_datagrid/datagrid.dart';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use whatever state management you want to use. I prefer &lt;strong&gt;provider&lt;/strong&gt; so i am using that.&lt;/p&gt;

&lt;p&gt;For this add the Provider dependency to your pubspec.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
    provider: ^latest_version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the provider files in main.dart&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: multiProvider,
      child: MaterialApp(
        builder: (context, child) =&amp;gt; MediaQuery(
          data: MediaQuery.of(context).copyWith(
            alwaysUse24HourFormat: true,
          ),
          child: child!,
        ),
        debugShowCheckedModeBanner: false,
        title: 'Data Grid',
        home: const Dashboard(),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I prefer a global file for holding all providers, So make multi_provider.dart file and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import 'package:provider/provider.dart';
import '../screens/dashboard/controller/dash_controller.dart';

var multiProvider = [

  /// DashProvider ///
  ChangeNotifierProvider&amp;lt;DashProvider&amp;gt;(
    create: (_) =&amp;gt; DashProvider(),
    lazy: true,
  ),

];

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that we need to add our variables to dashboard provider, i am using a rest api for the data u can use firebase as well.&lt;br&gt;
Add the following code to provider file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Initialize ur api service class
ApiService apiService = ApiService();

final GlobalKey&amp;lt;SfDataGridState&amp;gt; key = GlobalKey&amp;lt;SfDataGridState&amp;gt;();

bool _isLoading = false;
bool get isLoading =&amp;gt; _isLoading;

//Add u header columns
  List&amp;lt;GridColumn&amp;gt; grid = [
    GridColumn(
        columnName: 'ID',
        label: Container(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            alignment: Alignment.center,
            child:  Text(
              'Vehicle',
              style: TextStyle(color: white),
              overflow: TextOverflow.ellipsis,
            ))),
  ];

  late ReportDetailData reportDetailData;
  List&amp;lt;DataModel&amp;gt; _data = [];
  List&amp;lt;DataModel&amp;gt; get data =&amp;gt; _data;

  Future&amp;lt;void&amp;gt; getData(BuildContext context) async {
    _isLoading = true;
    notifyListeners();
    apiService.getData().then((response) {
      List&amp;lt;dynamic&amp;gt; data = json.decode(response.body);
      if (response.statusCode == 200 &amp;amp;&amp;amp; data.toString() != "[]") {
        _data = data.map((data) =&amp;gt; DataModel.fromJson(data)).toList();

        reportDetailData = ReportDetailData(data: _data);
        _isLoading = false;
        notifyListeners();
      } else if (response.statusCode == 200 &amp;amp;&amp;amp; data.toString() == "[]") {
        _isLoading = false;
        notifyListeners();
      } else {
        _isLoading = false;
        notifyListeners();
      }
    });
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After doing all that come to ur dashboard.dart file and call the api on initState.&lt;/p&gt;

&lt;p&gt;Now Add the following code to initState:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      context.read&amp;lt;DashProvider&amp;gt;().getData(context);
    });
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the widget part add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Add this to the Scaffold body
context.watch&amp;lt;DashProvider&amp;gt;().isLoading
            ? const Align(
                alignment: Alignment.center,
                child: Text("Loading....),
              )
            : SfDataGridTheme(
                    data: SfDataGridThemeData(headerColor: Colors.black),
                    child: SfDataGrid(

                        gridLinesVisibility: GridLinesVisibility.both,
                        rowsPerPage: 20,
                        key: context.read&amp;lt;DashProvider&amp;gt;().key,
                        source: context
                            .read&amp;lt;DashProvider&amp;gt;()
                            .reportDetailData,
                        allowSorting: true,
                        columnWidthMode: ColumnWidthMode.fill,
                        selectionMode: SelectionMode.multiple,
                        navigationMode: GridNavigationMode.cell,
                        columns: context.read&amp;lt;DashProvider&amp;gt;().grid),
                  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Finally don't forget to add the reportDetailData class..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add the following code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ReportDetailData extends DataGridSource {
  /// Creates the employee data source class with required details.
  ReportDetailData({required List&amp;lt;DataModel&amp;gt; data}) {
    _employeeData = data.map&amp;lt;DataGridRow&amp;gt;((DataModel e) {
      return DataGridRow(cells: &amp;lt;DataGridCell&amp;gt;[
        DataGridCell&amp;lt;String&amp;gt;(
            columnName: 'ID',
            value: e.id.toString() == "null" ? "N/A" : e.id.toString()),

    }).toList();
  }

  List&amp;lt;DataGridRow&amp;gt; _employeeData = &amp;lt;DataGridRow&amp;gt;[];

  @override
  List&amp;lt;DataGridRow&amp;gt; get rows =&amp;gt; _employeeData;

  @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map&amp;lt;Widget&amp;gt;((DataGridCell cell) {
      return Container(
        alignment: Alignment.center,
        child: Text(
          cell.value.toString(),
          style: TextStyle(fontSize: 15),
          textAlign: TextAlign.center,
        ),
      );
    }).toList());
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all u need to do run the app by using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$flutter run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hurray u finally made a data grid using Syncfusion package flutter.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Result:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53icstvwqisvc15v8qgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53icstvwqisvc15v8qgh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep sure to check out my packages and leave a suggestion:&lt;br&gt;
&lt;a href="https://pub.dev/packages/fancy_button_new" rel="noopener noreferrer"&gt;https://pub.dev/packages/fancy_button_new&lt;/a&gt;&lt;br&gt;
&lt;a href="https://pub.dev/packages/fancy_field_new" rel="noopener noreferrer"&gt;https://pub.dev/packages/fancy_field_new&lt;/a&gt;&lt;/p&gt;

</description>
      <category>syncfusion</category>
      <category>flutter</category>
      <category>mobile</category>
      <category>dart</category>
    </item>
    <item>
      <title>Publish Flutter Package on pub.dev</title>
      <dc:creator>Muhammad Manan</dc:creator>
      <pubDate>Tue, 24 Jan 2023 12:47:48 +0000</pubDate>
      <link>https://forem.com/loopstack33/publish-flutter-package-on-pubdev-2g6p</link>
      <guid>https://forem.com/loopstack33/publish-flutter-package-on-pubdev-2g6p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Preparing to publish&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When publishing a package, it’s important to follow the pubspec format and package layout conventions. Some of these are required in order for others to be able to use your package. Others are suggestions to help make it easier for users to understand and work with your package. In both cases, pub tries to help you by pointing out what changes will help make your package play nicer with the Dart ecosystem. There are a few additional requirements for uploading a package:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You must include a LICENSE file. We recommend the BSD 3-clause license, which the Dart and Flutter teams typically use. However, you can use any license that’s appropriate for your package. You must also have the legal right to redistribute anything that you upload as part of your package.&lt;br&gt;
Your package must be smaller than 100 MB after gzip compression. If it’s too large, consider splitting it into multiple packages, using a .pubignore file to remove unnecessary content, or cutting down on the number of included resources or examples.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your package should depend only on hosted dependencies (from the default pub package server) and SDK dependencies (sdk: flutter). These restrictions ensure that dependencies of your packages cannot become unavailable in the future.&lt;br&gt;
You must have a Google Account, which pub uses to manage package upload permissions. Your Google Account can be associated with a Gmail address or with any other email address.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pub uses the contents of a few files to create a page for your package at pub.dev/packages/. Here are the files that affect how your package’s page looks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;README.md: The README.md file is the main content featured in your package’s page. The file’s contents are rendered as Markdown. For guidance on how to write a great README, see Writing package pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CHANGELOG.md: Your package’s CHANGELOG.md file, if found, is also featured in a tab on your package’s page, so that developers can read it right from pub.dev. The file’s contents are rendered as Markdown.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The pubspec: Your package’s pubspec.yaml file is used to fill out details about your package on the right side of your package’s page, like its description, homepage, etc.&lt;br&gt;
Publishing your package&lt;br&gt;
Use the dart pub publish command to publish your package for the first time, or to update it to a new version.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Performing a dry run&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To test how dart pub publish will work, you can perform a dry run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ dart pub publish --dry-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hurray!! NOW FINALLY you can publish now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Publishing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you’re ready to publish your package, remove the --dry-run argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ dart pub publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will receive and email of package published on pub.dev and u can now flex with your friends about the package u uploaded and saved developers life…&lt;/p&gt;

&lt;p&gt;Keep sure to check out my packages and leave a suggestion:&lt;br&gt;
&lt;a href="https://pub.dev/packages/fancy_button_new" rel="noopener noreferrer"&gt;https://pub.dev/packages/fancy_button_new&lt;/a&gt;&lt;br&gt;
&lt;a href="https://pub.dev/packages/fancy_field_new" rel="noopener noreferrer"&gt;https://pub.dev/packages/fancy_field_new&lt;/a&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>remote</category>
      <category>startup</category>
    </item>
  </channel>
</rss>
