如何在 Summernote Flutter 中滚动

how to scroll in summernote flutter

提问人:Stefan Ruben 提问时间:8/31/2023 更新时间:9/1/2023 访问量:64

问:

我正在使用 summernote 文本编辑器,但我不知道如何在 summernote 文本编辑器中滚动。 这是我的代码:

FlutterSummernote(
  widthImage: '40%',
  hasAttachment: true,
  hint: "Your text here...",
  key: _keyWhatToDo,
  height: 450,
  customToolbar: """
    [
      ['style', ['bold', 'italic', 'underline']],
      ['font', ['strikethrough']],
      ['fontsize', ['fontsize']],
      ['color', ['color']],
      ['para', ['ul', 'ol', 'paragraph']],
    ]"""
),

如果有什么问题,请告诉我或给我一些建议。

颤振 Summernote

评论


答:

0赞 Dharam Budh 8/31/2023 #1

它按预期工作。我不知道你遇到了哪个问题。 尝试将下面提到的代码写入您的文件并检查结果。main.dart

import "package:flutter/material.dart";
import "package:flutter_summernote/flutter_summernote.dart";

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<FlutterSummernoteState> _keyWhatToDo = GlobalKey();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _keyWhatToDo.currentState?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            // Your widgets
            FlutterSummernote(
              widthImage: "40%",
              hasAttachment: true,
              hint: "Your text here...",
              key: _keyWhatToDo,
              height: 450,
              customToolbar: """
              [
                ['style', ['bold', 'italic', 'underline']],
                ['font', ['strikethrough']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
              ]""",
            ),
            // Your widgets
          ],
        ),
      ),
    );
  }
}

评论

0赞 Stefan Ruben 8/31/2023
如果与 SingleChildScrollView 结合使用,似乎存在问题。但感谢您的帮助
0赞 Dharam Budh 8/31/2023
你想要那个吗?如果你说,我可以用 SingleChildScrollView 试试。
0赞 Stefan Ruben 9/1/2023
当然,你能帮我吗?
0赞 Dharam Budh 9/1/2023
我给出一个新的答案。一探究竟。
0赞 Dharam Budh 9/1/2023 #2

更新:根据您的要求,结合 .FlutterSummernoteSingleChildScrollView

它按预期工作。我不知道你遇到了哪个问题。尝试将下面提到的代码写入main.dart文件并检查结果。

import "package:flutter/material.dart";
import "package:flutter_summernote/flutter_summernote.dart";

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<FlutterSummernoteState> _keyWhatToDo = GlobalKey();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _keyWhatToDo.currentState?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Container(height: 200, color: Colors.blue),
              Container(height: 200, color: Colors.pink),
              FlutterSummernote(
                widthImage: "40%",
                hasAttachment: true,
                hint: "Your text here...",
                key: _keyWhatToDo,
                height: 450,
                customToolbar: """
              [
                ['style', ['bold', 'italic', 'underline']],
                ['font', ['strikethrough']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
              ]""",
              ),
              Container(height: 200, color: Colors.orange),
              Container(height: 200, color: Colors.green),
            ],
          ),
        ),
      ),
    );
  }
}

评论

0赞 Stefan Ruben 9/1/2023
问题来了,summernote 文本无法滚动。有什么解决办法吗?
0赞 Dharam Budh 9/1/2023
所以,我们可以做一件事。根据键盘的外观,我们可以打开或关闭滚动。那东西是零散的,但它正在工作。我刚刚做到了。
0赞 Dharam Budh 9/1/2023
物理:MediaQuery.of(context).viewInsets.bottom == 0 ?const ScrollPhysics() : const NeverScrollableScrollPhysics(),在 SingleChildScrollView 中设置此属性。
0赞 Stefan Ruben 9/1/2023
它有效,谢谢你的帮助
0赞 Dharam Budh 9/1/2023
高度赞赏投票和接受答案。如果可能的话,请考虑一下。