From c11c631229773aa5cc949b71bb06271c3ffba520 Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Sun, 14 Aug 2022 22:48:13 +0800 Subject: [PATCH] www --- lib/model/hive/ContentHive.dart | 27 +++++++++++ lib/model/hive/ContentHive.g.dart | 59 ++++++++++++++++++++++++ lib/model/hive/content_list_model.dart | 19 ++++++++ lib/model/hive/content_list_model.g.dart | 13 ++++++ lib/providers/content_provider.dart | 14 ++++++ lib/ui/home/content_page.dart | 17 +++---- 6 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 lib/model/hive/ContentHive.dart create mode 100644 lib/model/hive/ContentHive.g.dart create mode 100644 lib/model/hive/content_list_model.dart create mode 100644 lib/model/hive/content_list_model.g.dart create mode 100644 lib/providers/content_provider.dart diff --git a/lib/model/hive/ContentHive.dart b/lib/model/hive/ContentHive.dart new file mode 100644 index 0000000..0e3c3b4 --- /dev/null +++ b/lib/model/hive/ContentHive.dart @@ -0,0 +1,27 @@ +import 'package:hive/hive.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; + +import 'content_list_model.dart'; +part 'ContentHive.g.dart'; + + +@JsonSerializable() +@HiveType(typeId:2) +class ContentHive extends Equatable{ + @HiveField(0) + final int id; + @HiveField(1) + final String content; + @HiveField(2) + final List list; + factory ContentHive.fromJson(Map json) =>_$ContentHiveFromJson(json); + + const ContentHive({ + required this.id, + required this.content, + required this.list, + }); + @override + List get props => [id,content,list]; +} \ No newline at end of file diff --git a/lib/model/hive/ContentHive.g.dart b/lib/model/hive/ContentHive.g.dart new file mode 100644 index 0000000..6bca3b7 --- /dev/null +++ b/lib/model/hive/ContentHive.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'ContentHive.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class ContentHiveAdapter extends TypeAdapter { + @override + final int typeId = 0; + + @override + ContentHive read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return ContentHive( + id: fields[0] as int, + content: fields[1] as String, + list: (fields[3] as List).cast(), + ); + } + + @override + void write(BinaryWriter writer, ContentHive obj) { + writer + ..writeByte(3) + ..writeByte(0) + ..write(obj.id) + ..writeByte(1) + ..write(obj.content) + ..writeByte(3) + ..write(obj.list); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ContentHiveAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ContentHive _$ContentHiveFromJson(Map json) => ContentHive( + id: json['id'] as int, + content: json['content'] as String, + list: (json['list'] as List) + .map((e) => ContentListModel.fromJson(e as Map)) + .toList(), + ); diff --git a/lib/model/hive/content_list_model.dart b/lib/model/hive/content_list_model.dart new file mode 100644 index 0000000..c8ae6f2 --- /dev/null +++ b/lib/model/hive/content_list_model.dart @@ -0,0 +1,19 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +part 'content_list_model.g.dart'; + + +@JsonSerializable() +class ContentListModel extends Equatable{ + final int index; + final String content; + factory ContentListModel.fromJson(Map json) =>_$ContentListModelFromJson(json); + + + const ContentListModel({ + required this.index, + required this.content, + }); + @override + List get props => [index,content]; +} \ No newline at end of file diff --git a/lib/model/hive/content_list_model.g.dart b/lib/model/hive/content_list_model.g.dart new file mode 100644 index 0000000..f512f2b --- /dev/null +++ b/lib/model/hive/content_list_model.g.dart @@ -0,0 +1,13 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'content_list_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ContentListModel _$ContentListModelFromJson(Map json) => + ContentListModel( + index: json['index'] as int, + content: json['content'] as String, + ); diff --git a/lib/providers/content_provider.dart b/lib/providers/content_provider.dart new file mode 100644 index 0000000..1170def --- /dev/null +++ b/lib/providers/content_provider.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; +import 'package:hive/hive.dart'; + +import '../model/hive/ContentHive.dart'; + +class ContentListModel extends ChangeNotifier{ + late Box _regionBox; + List _regions=[]; + List get regions=>_regions; + Future init() async{} + // _regionBox = await Hive.openBox("ContentListBox"); + // var + +} \ No newline at end of file diff --git a/lib/ui/home/content_page.dart b/lib/ui/home/content_page.dart index df1d9d2..f002857 100644 --- a/lib/ui/home/content_page.dart +++ b/lib/ui/home/content_page.dart @@ -1,9 +1,10 @@ - +import 'dart:io'; import 'package:call_log/call_log.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_sms/flutter_sms.dart'; import 'package:get_phone_number/get_phone_number.dart'; +import 'package:hive/hive.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:project_telephony/base/base_style.dart'; import 'package:project_telephony/ui/home/content_details_page.dart'; @@ -72,11 +73,7 @@ class _ContentPageState extends State { }, )); } else { - bool? permissionsGranted = await telephony.requestPhonePermissions; - final Iterable result = await CallLog.query(); - phoneNum = result.first.number!; - - print(phoneNum); + // bool? permissionsGranted = await telephony.requestPhonePermissions; // print(permissionsGranted); // if(permissionsGranted!){ // print(content); @@ -95,10 +92,10 @@ class _ContentPageState extends State { // message: content, // isMultipart: true // ); - List recipents=[ - phoneNum - ]; - _sendSMS(content,recipents); + // List recipents=[ + // phoneNum + // ]; + // _sendSMS(content,recipents); // String phoneNumber = await GetPhoneNumber().get(); // print('getPhoneNumber result: $phoneNumber'); }