Skip to content

Commit

Permalink
Merge pull request #2 from SummerRock/flutter_v1
Browse files Browse the repository at this point in the history
Flutter v1
  • Loading branch information
SummerRock authored Mar 3, 2024
2 parents 5e0d2f2 + 5f4a920 commit 30a41ee
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 1 deletion.
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ dependencies { // 项目需要的依赖
implementation project(path: ':commonmodule')
implementation project(path: ':monitor')
implementation project(path: ':react')
implementation project(':flutter')

/** 上拉刷新、下拉加载 **/
implementation('com.scwang.smartrefresh:SmartRefreshLayout:1.1.0')
Expand Down
7 changes: 7 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="28">
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="@style/AppTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name=".setting.SettingsActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.Locale;

import io.flutter.embedding.android.FlutterActivity;


public class MineFragment extends BaseFragment<MineViewModel, FragmentMineBinding> {

Expand All @@ -45,6 +47,12 @@ protected void performAction() {
});
final TextView userNameText = binding.profileName;
final TextView coinCountText = binding.userCoinCount;
coinCountText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(FlutterActivity.withNewEngine().initialRoute("/coin_rank").build(requireContext()));
}
});
viewModel.getMessageCountLiveData().observe(getViewLifecycleOwner(), new Observer<NetworkModel<Integer>>() {
@Override
public void onChanged(NetworkModel<Integer> integerNetworkModel) {
Expand All @@ -55,7 +63,7 @@ public void onChanged(NetworkModel<Integer> integerNetworkModel) {
viewModel.getLoginInfo().observe(getViewLifecycleOwner(), loginVo -> {
if (loginVo != null) {
userNameText.setText(loginVo.getUsername());
coinCountText.setText(String.format(Locale.getDefault(), "金币数量: %d", loginVo.getCoinCount()));
coinCountText.setText(String.format(Locale.getDefault(), "当前积分: %d", loginVo.getCoinCount()));
} else {
userNameText.setText("未登录");
coinCountText.setVisibility(View.GONE);
Expand Down
49 changes: 49 additions & 0 deletions android/flutter_module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.DS_Store
.dart_tool/

.pub/

.idea/
.vagrant/
.sconsign.dblite
.svn/

migrate_working_dir/

*.swp
profile

DerivedData/

.generated/

*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3

!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3

xcuserdata

*.moved-aside

*.pyc
*sync/
Icon?
.tags*

build/
.android/
.ios/
.flutter-plugins
.flutter-plugins-dependencies

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
10 changes: 10 additions & 0 deletions android/flutter_module/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "41456452f29d64e8deb623a3c927524bcf9f111b"
channel: "stable"

project_type: module
11 changes: 11 additions & 0 deletions android/flutter_module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# flutter_module

A new Flutter module project.

## Getting Started

For help getting started with Flutter development, view the online
[documentation](https://flutter.dev/).

For instructions integrating Flutter modules to your existing applications,
see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app).
4 changes: 4 additions & 0 deletions android/flutter_module/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
53 changes: 53 additions & 0 deletions android/flutter_module/lib/demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';

class TitleSection extends StatelessWidget {
const TitleSection({
super.key,
required this.name,
required this.location,
});

final String name;
final String location;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(32),
child: Row(
children: [
Expanded(
/*1*/
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/*2*/
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
name,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Text(
location,
style: TextStyle(
color: Colors.grey[500],
),
),
],
),
),
/*3*/
Icon(
Icons.star,
color: Colors.red[500],
),
const Text('41'),
],
),
);
}
}
37 changes: 37 additions & 0 deletions android/flutter_module/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_module/pages/coinrank/CoinRankList.dart';

import 'demo.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 running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in a Flutter IDE). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
initialRoute: '/', // 指定初始路由
routes: {
'/demo': (context) => const TitleSection(
name: 'demo_v1',
location: 'loc_v2',
),
'/coin_rank': (context) => const CoinRankList(title: '积分排行榜-Flutter'),
},
);
}
}
91 changes: 91 additions & 0 deletions android/flutter_module/lib/pages/coinrank/CoinRankList.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'package:flutter/material.dart';

class CoinRankList extends StatefulWidget {
const CoinRankList({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<CoinRankList> createState() => _CoinRankListState();
}

class _CoinRankListState extends State<CoinRankList> {
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
void initState() {

}

@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(
// 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.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// 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).
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.
);
}
}
Loading

0 comments on commit 30a41ee

Please sign in to comment.