mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-08 19:17:53 +08:00
change ui to flutter
This commit is contained in:
4
ui/lib/APIs.dart
Normal file
4
ui/lib/APIs.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
class APIs {
|
||||
static const _baseUrl = "http://127.0.0.1:8080";
|
||||
static const searchUrl = "$_baseUrl/api/v1/tv/search";
|
||||
}
|
||||
107
ui/lib/main.dart
Normal file
107
ui/lib/main.dart
Normal file
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ui/navdrawer.dart';
|
||||
import 'package:ui/search.dart';
|
||||
|
||||
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(
|
||||
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: Row(
|
||||
children: <Widget>[
|
||||
NavDrawer(),
|
||||
const SearchPage(),
|
||||
],
|
||||
)),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
39
ui/lib/navdrawer.dart
Normal file
39
ui/lib/navdrawer.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NavDrawer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Drawer(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: Icon(Icons.input),
|
||||
title: Text('Welcome'),
|
||||
onTap: () => {},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.verified_user),
|
||||
title: Text('Profile'),
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.settings),
|
||||
title: Text('Settings'),
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.border_color),
|
||||
title: Text('Feedback'),
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.exit_to_app),
|
||||
title: Text('Logout'),
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
123
ui/lib/search.dart
Normal file
123
ui/lib/search.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:ui/APIs.dart';
|
||||
|
||||
class SearchPage extends StatefulWidget {
|
||||
const SearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _SearchPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SearchPageState extends State<SearchPage> {
|
||||
List<dynamic> list = List.empty();
|
||||
final tmdbImgBaseUrl = "https://image.tmdb.org/t/p/w500/";
|
||||
|
||||
void _queryResults(String q) async {
|
||||
final dio = Dio();
|
||||
var resp = await dio.get(APIs.searchUrl, queryParameters: {"query": q});
|
||||
//var dy = jsonDecode(resp.data.toString());
|
||||
|
||||
print("search page results: ${resp.data}");
|
||||
|
||||
var rsp = resp.data as Map<String, dynamic>;
|
||||
var data = rsp["data"] as Map<String, dynamic>;
|
||||
var results = data["results"] as List<dynamic>;
|
||||
|
||||
setState(() {
|
||||
list = results;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var cards = List<Widget>.empty(growable: true);
|
||||
for (final item in list) {
|
||||
var m = item as Map<String, dynamic>;
|
||||
cards.add(Card(
|
||||
margin: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: SizedBox(
|
||||
width: 150,
|
||||
height: 200,
|
||||
child: Image.network(
|
||||
tmdbImgBaseUrl + m["poster_path"],
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: ListTile(title: Text(m["name"])),
|
||||
),
|
||||
Flexible(child: Text(m["overview"]))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
return Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
autofocus: true,
|
||||
onSubmitted: (value) => _queryResults(value),
|
||||
decoration: const InputDecoration(
|
||||
labelText: "搜索",
|
||||
hintText: "搜索剧集名称",
|
||||
prefixIcon: Icon(Icons.search)),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: cards,
|
||||
))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SearchBarApp extends StatefulWidget {
|
||||
const SearchBarApp({
|
||||
super.key,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final ValueChanged<String> onChanged;
|
||||
@override
|
||||
State<SearchBarApp> createState() => _SearchBarAppState();
|
||||
}
|
||||
|
||||
class _SearchBarAppState extends State<SearchBarApp> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SearchAnchor(
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
return SearchBar(
|
||||
controller: controller,
|
||||
padding: const WidgetStatePropertyAll<EdgeInsets>(
|
||||
EdgeInsets.symmetric(horizontal: 16.0)),
|
||||
onSubmitted: (value) => {widget.onChanged(controller.text)},
|
||||
leading: const Icon(Icons.search),
|
||||
);
|
||||
}, suggestionsBuilder: (BuildContext context, SearchController controller) {
|
||||
return List<ListTile>.generate(0, (int index) {
|
||||
final String item = 'item $index';
|
||||
return ListTile(
|
||||
title: Text(item),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
controller.closeView(item);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
0
ui/lib/server_response.dart
Normal file
0
ui/lib/server_response.dart
Normal file
Reference in New Issue
Block a user