datagrid_custom 0.0.8
datagrid_custom: ^0.0.8 copied to clipboard
The Syncfusion Flutter DataGrid is used to display and manipulate data in a tabular view. Its rich feature set includes different types of columns, selections, column sizing, etc.
example/lib/main.dart
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_core/theme.dart';
import 'tabela_widget.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: Locale('pt'),
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Scaffold(
body: Container(
child: const MyHomePage(title: 'Flutter Demo Home Page'),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var listaItems = [
TabelaGenericaDataTypeStruct(
coluna1: 'Teste',
valor1: '4',
tipo1: 'Int',
coluna2: 'A',
valor2: '20,51',
tipo2: 'Double',
),
TabelaGenericaDataTypeStruct(
coluna1: 'Teste',
valor1: '3',
tipo1: 'Int',
coluna2: 'A',
valor2: '15,53',
tipo2: 'Double',
),
TabelaGenericaDataTypeStruct(
coluna1: 'Teste',
valor1: '2',
tipo1: 'Int',
coluna2: 'A',
valor2: '5,45',
tipo2: 'Double',
),
TabelaGenericaDataTypeStruct(
coluna1: 'Teste',
valor1: '1',
tipo1: 'Int',
coluna2: 'A',
valor2: '35,99',
tipo2: 'Double',
),
];
return Theme(
data: ThemeData(
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
)),
),
child: TabelaWidget(
colunas: [
Colunas(
nome: 'Teste',
tipo: 'String',
),
Colunas(nome: 'A', tipo: 'Double')
],
dados: listaItems,
));
}
}
class TabelaGenericaDataTypeStruct {
final String coluna1;
final String valor1;
final String imagem1;
final String tipo1;
final String coluna2;
final String valor2;
final String imagem2;
final String tipo2;
final String coluna3;
final String valor3;
final String coluna4;
final String valor4;
final String coluna5;
final String valor5;
final String coluna6;
final String valor6;
TabelaGenericaDataTypeStruct({
this.coluna1 = '',
this.valor1 = '',
this.coluna2 = '',
this.valor2 = '',
this.coluna3 = '',
this.valor3 = '',
this.coluna4 = '',
this.valor4 = '',
this.coluna5 = '',
this.valor5 = '',
this.coluna6 = '',
this.valor6 = '',
this.imagem1 = '',
this.imagem2 = '',
this.tipo1 = 'String',
this.tipo2 = 'String',
});
}
class Colunas {
double? tamanho = null;
String nome = "";
final String tipo;
Colunas({required this.nome, this.tamanho, this.tipo = "String"});
}