initializing

This commit is contained in:
2024-03-28 22:44:55 +01:00
parent 23a5448094
commit 5d17cc83e6
8 changed files with 655 additions and 123 deletions
+82
View File
@@ -0,0 +1,82 @@
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class Movie {
int movieID;
String movieTitle;
String overview;
DateTime releaseDate;
int state;
String resolution;
Movie({
required this.movieID,
required this.movieTitle,
required this.overview,
required this.releaseDate,
required this.state,
required this.resolution,
});
factory Movie.fromJson(Map<String, dynamic> json) {
return Movie(
movieID: int.parse(json['movieID']),
movieTitle: json['movieTitle'] as String,
overview: json['overview'] as String,
releaseDate: DateTime.parse(json['releaseDate']),
state: int.parse(json['state']),
resolution: json['resolution'] as String,
);
}
}
class MovieDataSource extends DataGridSource {
/// Creates the employee data source class with required details.
MovieDataSource(this.movies) {
buildDataGridRow();
}
void buildDataGridRow() {
_movieDataGridRows = movies
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'movieID', value: e.movieID),
DataGridCell<int>(columnName: 'state', value: e.state),
DataGridCell<String>(
columnName: 'movieTitle', value: e.movieTitle),
DataGridCell<String>(
columnName: 'releaseDate',
value: DateFormat('yyyy-MM-dd').format(e.releaseDate)),
DataGridCell<String>(
columnName: 'resolution', value: e.resolution),
DataGridCell<String>(columnName: 'overview', value: e.overview),
]))
.toList();
}
List<Movie> movies = [];
List<DataGridRow> _movieDataGridRows = [];
@override
List<DataGridRow> get rows => _movieDataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString()),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}
+24 -109
View File
@@ -1,4 +1,16 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:multimedia/widgets/tabsScreen.dart';
final theme = ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
brightness: Brightness.dark,
seedColor: const Color.fromARGB(255, 131, 57, 0),
),
textTheme: GoogleFonts.latoTextTheme(),
);
void main() {
runApp(const MyApp());
@@ -11,115 +23,18 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
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: 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> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
// theme: theme,
title: 'Multimedia',
// theme: ThemeData.dark().copyWith(
// useMaterial3: true,
// colorScheme: ColorScheme.fromSeed(
// seedColor: const Color.fromARGB(255, 147, 229, 250),
// brightness: Brightness.dark,
// surface: const Color.fromARGB(255, 42, 51, 59),
// ),
// scaffoldBackgroundColor: const Color.fromARGB(255, 50, 58, 60),
// ),
home: const TabsScreen(),
);
}
}
+206
View File
@@ -0,0 +1,206 @@
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
import 'package:syncfusion_flutter_core/theme.dart';
import 'package:multimedia/data/movies.dart';
Color _kColorInit = const Color.fromARGB(255, 192, 192, 192);
Color _kColorProg = const Color.fromARGB(255, 0, 0, 192);
Color _kColorDone = const Color.fromARGB(255, 0, 192, 0);
// if(m_state == 1)
// color = "background-color: #C0C0C0;";
// else if(m_state == 2)
// color = "background-color: #0000C0; color: #FFFFFF";
// else
// color = "background-color: #00C000;";
class MoviesScreen extends StatefulWidget {
const MoviesScreen({
super.key,
});
@override
State<StatefulWidget> createState() => _MoviesScreenState();
}
class _MoviesScreenState extends State<MoviesScreen> {
final DataGridController _dataGridController = DataGridController();
late MovieDataSource movieDataSource;
List<GridColumn> _columns = [];
Future<List<Movie>> generateMovieList() async {
// Give your PHP URL. It may be online URL o local host URL.
// Follow the steps provided in the below KB to configure the mysql using
// XAMPP and get the local host php link,
///
Uri url = Uri.http('192.168.0.70', 'multimedia.php');
final response = await http.get(url);
var list = json.decode(response.body);
// Convert the JSON to List collection.
List<Movie> _movies =
await list.map<Movie>((json) => Movie.fromJson(json)).toList();
movieDataSource = MovieDataSource(_movies);
return _movies;
}
List<GridColumn> getColumns() {
return <GridColumn>[
GridColumn(
columnName: 'movieID',
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
alignment: Alignment.centerLeft,
child: const Text('movieID'))),
GridColumn(
columnName: 'state',
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
alignment: Alignment.centerLeft,
child: const Text('state'))),
GridColumn(
columnName: 'movieTitle',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: const Text('Title'))),
GridColumn(
columnName: 'releaseDate',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: const Text('First Aired'))),
GridColumn(
columnName: 'resolution',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: const Text('Resolution'))),
GridColumn(
columnName: 'overview',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: const Text('Overview'))),
];
}
@override
void initState() {
super.initState();
_columns = getColumns();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<Object>(
future: generateMovieList(),
builder: (context, data) {
return data.hasData
?
SfDataGridTheme(
data: const SfDataGridThemeData(
headerColor: Color(0xff009889),
),
child:
SfDataGrid(
source: movieDataSource,
selectionMode: SelectionMode.single,
navigationMode: GridNavigationMode.row,
columns: _columns,
controller: _dataGridController,
columnWidthMode: ColumnWidthMode.fill,
),
)
: const Center(
child: CircularProgressIndicator(
strokeWidth: 2,
value: 0.8,
),
);
},
),
);
}
}
class MovieDataSource extends DataGridSource {
/// Creates the employee data source class with required details.
MovieDataSource(this.movies) {
buildDataGridRow();
}
void buildDataGridRow() {
_movieDataGridRows = movies
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'movieID', value: e.movieID),
DataGridCell<int>(columnName: 'state', value: e.state),
DataGridCell<String>(
columnName: 'movieTitle', value: e.movieTitle),
DataGridCell<String>(
columnName: 'releaseDate',
value: DateFormat('yyyy-MM-dd').format(e.releaseDate)),
DataGridCell<String>(
columnName: 'resolution', value: e.resolution),
DataGridCell<String>(columnName: 'overview', value: e.overview),
]))
.toList();
}
List<Movie> movies = [];
List<DataGridRow> _movieDataGridRows = [];
@override
List<DataGridRow> get rows => _movieDataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
Color colorBG = Colors.white;
Color colorFG = Colors.black;
if (e.columnName == 'movieTitle') {
int state = row.getCells().toList()[1].value;
if (state == 1) {
colorBG = _kColorInit;
} else if (state == 2) {
colorBG = _kColorProg;
colorFG = Colors.white;
} else {
colorBG = _kColorDone;
}
}
return Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.all(8.0),
color: colorBG,
child: Text(
e.value.toString(),
style: TextStyle(color: colorFG),
),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}
+62
View File
@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import 'package:multimedia/widgets/tvshowsScreen.dart';
import 'package:multimedia/widgets/moviesScreen.dart';
import 'package:multimedia/data/movies.dart';
class TabsScreen extends StatefulWidget {
const TabsScreen({super.key});
@override
State<TabsScreen> createState() {
return _TabsScreenState();
}
}
class _TabsScreenState extends State<TabsScreen> {
@override
void initState() {
super.initState();
}
int _selectedPageIndex = 0;
void _selectPage(int index) {
setState(() {
_selectedPageIndex = index;
});
}
@override
Widget build(BuildContext context) {
Widget activePage = const TVShowsScreen();
var activePageTitle = 'TV Shows';
if (_selectedPageIndex == 1) {
activePage = MoviesScreen();
activePageTitle = 'Movies';
}
return Scaffold(
appBar: AppBar(
title: Text(activePageTitle),
),
body: activePage,
bottomNavigationBar: BottomNavigationBar(
onTap: _selectPage,
currentIndex: _selectedPageIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.tv_outlined),
label: 'TVShows',
),
BottomNavigationBarItem(
icon: Icon(Icons.movie),
label: 'Movies',
),
],
),
);
}
}
+75
View File
@@ -0,0 +1,75 @@
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
Color _kColGrey = const Color.fromARGB(255, 192, 192, 192);
Color _kColBlue = const Color.fromARGB(255, 0, 0, 192);
Color _kColGreen = const Color.fromARGB(255, 0, 192, 0);
Color _kColBlack = const Color.fromARGB(255, 0, 0, 0);
Color _kColWhite = const Color.fromARGB(255, 255, 255, 255);
double _kStateWidth = 6;
double _kStateHeight = 30;
class TVShowsScreen extends StatefulWidget {
const TVShowsScreen({
super.key,
});
@override
State<StatefulWidget> createState() => _TVShowsScreenState();
}
class _TVShowsScreenState extends State<TVShowsScreen>
with SingleTickerProviderStateMixin {
ui.Image? _image;
@override
void initState() {
super.initState();
_image = null;
_asyncInit();
}
Future<void> _asyncInit() async {
final image = await _generateImage();
setState(() {
_image = image;
});
}
void _drawEpisodeState(Canvas c, Paint p, double x, Color color) {
Offset p1 = Offset(x + _kStateWidth, 1);
Offset p2 = Offset(x + _kStateWidth, _kStateHeight - 1);
Rect rect = Rect.fromLTRB(x, 0, x + _kStateWidth, _kStateHeight);
p.style = PaintingStyle.fill;
p.color = color;
c.drawRect(rect, p);
p.color = Colors.black;
c.drawLine(p1, p2, p);
}
Future<ui.Image> _generateImage() async {
final Paint paint = Paint();
ui.PictureRecorder recorder = ui.PictureRecorder();
Canvas c = Canvas(recorder);
_drawEpisodeState(c, paint, _kStateWidth * 0, _kColBlack);
_drawEpisodeState(c, paint, _kStateWidth * 1, _kColBlue);
_drawEpisodeState(c, paint, _kStateWidth * 2, _kColGreen);
_drawEpisodeState(c, paint, _kStateWidth * 3, _kColGrey);
ui.Picture picture = recorder.endRecording();
final ui.Image image =
await picture.toImage(_kStateWidth.toInt() * 4, _kStateHeight.toInt());
return image;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _image != null ? RawImage(image: _image!) : const Text('loading'),
);
}
}