Created
December 16, 2021 07:49
-
-
Save Jahidul007/073c729de1c3c82e93338bedef1dc087 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
List<Person> person = List.empty(growable: true); | |
List<Map> data = [ | |
{"id": 1, "Firstname": "test", "lastName": "test"} | |
]; | |
@override | |
void initState() { | |
super.initState(); | |
data.forEach((row) { | |
person.add(Person.fromJson(row)); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar(title: Text('SQLite Example')), | |
body: Center( | |
child: ListView.builder( | |
itemCount: person.length, | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: Text('${person[index].firstname}.'), | |
); | |
}), | |
), | |
), | |
); | |
} | |
} | |
class Person { | |
Person({ | |
int? id, | |
String? firstname, | |
String? lastName, | |
}) { | |
_id = id; | |
_firstname = firstname; | |
_lastName = lastName; | |
} | |
Person.fromJson(dynamic json) { | |
_id = json['id']; | |
_firstname = json['Firstname']; | |
_lastName = json['lastName']; | |
} | |
int? _id; | |
String? _firstname; | |
String? _lastName; | |
int? get id => _id; | |
String? get firstname => _firstname; | |
String? get lastName => _lastName; | |
Map<String, dynamic> toJson() { | |
final map = <String, dynamic>{}; | |
map['id'] = _id; | |
map['Firstname'] = _firstname; | |
map['lastName'] = _lastName; | |
return map; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment