//科技政策一点通
List<dynamic> jsonData = [];
Future<void> fetchData() async {
try {
Dio dio = Dio();
String checkUrl = "http://192.168.183.241:7070/user/ALLname";
Response checkResponse = await dio.get(checkUrl);
jsonData = checkResponse.data;
} catch (e) {
print("Error: $e");
// 在这里处理异常情况,比如显示错误信息给用户
}
}
Future<String> fetchHtmlContent(String name) async {
Dio dio = Dio();
String checkUrl = "http://192.168.183.241:7070/user/ALLtext?name=$name";
Response checkResponse = await dio.get(checkUrl);
// 获取API返回的字符串列表
List<dynamic> jsonData = checkResponse.data;
// 假设你只需要返回列表中的第一个元素作为文本内容
if (jsonData.isNotEmpty) {
String textContent = jsonData.first;
return textContent;
} else {
// 如果列表为空,可以返回一个默认值或者抛出异常,具体根据你的需求来决定
return "No text content available";
}
}
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import '../Do/UserDao.dart';
Future<Widget> page1(String name) async {
String text = await fetchHtmlContent(name);
Widget richTextWidget = buildRichTextFromHtml(text);
return richTextWidget;
}
Widget buildRichTextFromHtml(String htmlText) {
return Html(
data: htmlText,
style: {
"p": Style(
padding: HtmlPaddings.zero, // 设置段落的内边距为零
fontSize: FontSize(16.0), // 设置段落的字体大小
lineHeight: LineHeight(1.2), // 设置段落的行高
),
},
);
}
import 'package:flutter/material.dart';
import 'package:test1/page/picture.dart';
import 'package:test1/page/record_column.dart';
import 'package:test1/page/video.dart'; // 导入video1页面
import 'package:test1/page/record_column.dart';
import '../Do/UserDao.dart';
import '../component/container.dart';
import '../component/drawer.dart';
import 'display.dart';
import 'openAL.dart';
import 'insert_column.dart';
import 'login.dart';
class ColumnPage1 extends StatelessWidget {
const ColumnPage1({Key? key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '心语航标',
theme: ThemeData(
primarySwatch: Colors.purple,
),
home: const ColumnScreen1(),
);
}
}
class ColumnScreen1 extends StatelessWidget {
const ColumnScreen1({Key? key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('专栏'),
bottom: const TabBar(
tabs: [
Tab(icon: Icon(Icons.home), text: '视频'),
Tab(icon: Icon(Icons.article), text: '精品图文'),
Tab(icon: Icon(Icons.contacts), text: '小说'),
],
),
),
body: TabBarView(
children: <Widget>[
Video1(),
Picture1(),
FutureBuilder(
future: fetchData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return Center(
child: Text('Error: ${snapshot.error}'),
);
} else {
return buildJsonDisplay(); // 你需要定义这个方法来构建你的 JSON 内容展示
}
},
),
],
),
),
);
}
}
void main() {
runApp(ColumnPage1());
}
import 'package:flutter/material.dart';
import 'package:test1/page/read.dart';
import '../Do/UserDao.dart';
Widget buildJsonDisplay() {
return Scaffold(
appBar: AppBar(
title: Text('小说'),
),
body: ListView.builder(
itemCount: jsonData.length,
itemBuilder: (context, index) {
var item = jsonData[index];
return Card(
child: ListTile(
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${item['name']}'),
],
),
onTap: () async {
Widget page = await page1(item['name']);
Navigator.push(context, MaterialPageRoute(builder: (context) => Scaffold(
appBar: AppBar(
title: Text('小说阅读'),
),
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(16.0),
child: Center(
child: page,
),
),
),
)));
},
),
);
},
),
);
}